pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 587 forks source link

PDFs (maybe all files?) not opening in iOS 13 #271

Closed ddl2829 closed 4 years ago

ddl2829 commented 4 years ago

Expected Behaviour

I have been generating and viewing PDFs in my apps using this plugin and cordova-plugin-file for quite some time. I was expecting this workflow to continue working as-is with the newest iOS update.

Actual Behaviour

After updating to iOS 13 documents no longer load. Screen Shot 2019-10-07 at 8 51 19 AM

Reproduce Scenario (including but not limited to)

Non functional both in iOS simulator and on actual device.

Steps to Reproduce

  1. Write a PDF file to the application's Library folder.
  2. Attempt to open the file with this plugin.
  3. Observe white screen as pictured above.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

iOS 13.0

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Cordova CLI info

cordova info

Here is the output:

cordova-lib@9.0.1 with:
  cordova-common@3.1.0
  cordova-create@2.0.0
  cordova-fetch@2.0.1
  cordova-serve@3.0.0

Environment:
  OS: darwin
  Node: v8.12.0
  npm: 6.4.1

Plugins:
  cordova-plugin-camera
  cordova-plugin-device
  cordova-plugin-dialogs
  cordova-plugin-file
  cordova-plugin-file-opener2
  cordova-plugin-whitelist
  cordova-plugin-wkwebview-engine

* snipped android section *

iOS platform:
  Xcode 11.0
  Build version 11A420a

Plugin version

cordova plugin version | grep cordova-plugin-file-opener2

Here is the output:

cordova-plugin-file-opener2 2.2.1 "File Opener2"

Sample Code that illustrates the problem

//pdf is a JSPDF object
const pdf = this.get('pdf');
window.requestFileSystem(1, 1024 * 1024 * 1024, function(fs) {
  console.log('Local file system granted');

  fs.root.getFile('temp.pdf', { create: true }, (fileEntry) => {
    console.log('got file handle');
    fileEntry.createWriter((fileWriter) => {
      console.log('file writer made');
      fileWriter.onwrite = function() {
        console.log('file done, opening ' + fileEntry.toURL());
        cordova.plugins.fileOpener2.open(
          fileEntry.toURL(),
          'application/pdf',
          function() {}, //success
          function() {} //error
        );
      };
      fileWriter.onerror = function(e) {
        console.log('Write failed: ' + e.toString());
      };
      console.log('writing output');
      fileWriter.write(pdf.output('blob'));
    });
  });
});

Logs taken while reproducing problem

2019-10-07 08:50:53.508255-0400 KLC Reporting[61351:5976955] Local file system granted
2019-10-07 08:50:53.515871-0400 KLC Reporting[61351:5976955] got file handle
2019-10-07 08:50:53.528027-0400 KLC Reporting[61351:5976955] file writer made
2019-10-07 08:50:53.528766-0400 KLC Reporting[61351:5976955] writing output
2019-10-07 08:50:53.549439-0400 KLC Reporting[61351:5976955] file done, opening file:///Users/dale/Library/Developer/CoreSimulator/Devices/430C8996-2F4B-471F-85EA-6E9917E959C2/data/Containers/Data/Application/E50E470F-6E6A-42B9-B742-918BDACE295B/Library/files/temp.pdf
2019-10-07 08:50:53.550365-0400 KLC Reporting[61351:5976955] Path parameter not encoded. Building file URL encoding it...
2019-10-07 08:50:53.550614-0400 KLC Reporting[61351:5976955] looking for file at file:///Users/dale/Library/Developer/CoreSimulator/Devices/430C8996-2F4B-471F-85EA-6E9917E959C2/data/Containers/Data/Application/E50E470F-6E6A-42B9-B742-918BDACE295B/Library/files/temp.pdf
2019-10-07 08:50:54.556770-0400 KLC Reporting[61351:5976955] [default] QLUbiquitousItemFetcher: <QLUbiquitousItemFetcher: 0x600003e1f750> could not create sandbox wrapper. Error: Error Domain=NSPOSIXErrorDomain Code=22 "couldn't issue sandbox extension com.apple.quicklook.readonly for '/Users/dale/Library/Developer/CoreSimulator/Devices/430C8996-2F4B-471F-85EA-6E9917E959C2/data/Containers/Data/Application/E50E470F-6E6A-42B9-B742-918BDACE295B/Library/files/temp.pdf': Invalid argument" UserInfo={NSDescription=couldn't issue sandbox extension com.apple.quicklook.readonly for '/Users/dale/Library/Developer/CoreSimulator/Devices/430C8996-2F4B-471F-85EA-6E9917E959C2/data/Containers/Data/Application/E50E470F-6E6A-42B9-B742-918BDACE295B/Library/files/temp.pdf': Invalid argument} #PreviewItem
ddl2829 commented 4 years ago

I appear to have done a poor job testing this- the issue in fact appears only in the simulator, which I can live with.

rondog commented 4 years ago

I feel like this issue is worth opening. Using file-opener2 2.x it was working on the simulator. Thankfully I checked on the device because of your comment. It is indeed only affecting the simulator.

whodeee commented 4 years ago

I am having this same issue on the device with iOS 13.3.1 - it is showing the Quick Look framework (photo above) instead of opening the file in the appropriate application on the device (PDF, PPTX, etc)