open_file icon indicating copy to clipboard operation
open_file copied to clipboard

Openning PDF in iOS

Open djireland opened this issue 4 years ago • 7 comments

I'm trying to open a PDF file that is local to the device on IOS 12. The PDF doesn't open but rather an action dialog box opens (attached) instead. Can we open the PDF directly ?

Here is the code I'm using:

     OpenFile.open(report.path,  type: "application/pdf", uti: "com.adobe.pdf");

and pubspec.yaml

 open_file: ^3.2.1

Thanks!

Simulator Screen Shot - iPhone 12 - 2021-05-21 at 13 56 46

djireland avatar May 21 '21 04:05 djireland

I have same issue

webnickell avatar Aug 02 '21 10:08 webnickell

I'm having the same issue for any kind of file on iOS, not just pdf.

Android also opens this dialog to choose with what program to open and after selection and then the files are opened as expected.

Allyanora avatar Aug 02 '21 11:08 Allyanora

If you are using a simulator, try it on a real machine

crazecoder avatar Aug 03 '21 02:08 crazecoder

If you are using a simulator, try it on a real machine

Oh no, we check it on different real IOS devices, this problem is not in simulator.

webnickell avatar Aug 03 '21 07:08 webnickell

I've tried it and it works, Make sure your PDF files are in the app's sandbox, Maybe that's the reason

crazecoder avatar Aug 04 '21 04:08 crazecoder

I have the same issue.

I found out the issue happens when the file extension is not '.pdf' even if Uti and Type are set.

I can reproduce the issue by using the flutter_cache_manager library that add a .file extension by default.

Hope it helps.

ygotthilf avatar Sep 02 '21 11:09 ygotthilf

The (ugly) workaround I found for the old ".file" files still in cache looks like:

    String path = file.path;

    if (path.endsWith('.file')) {
      final copied = await file.copy(
        path.replaceFirst(RegExp(r'\.file$'), '.pdf'),
      );

      path = copied.path;
    }

    await OpenFile.open(
      path,
      type:  'application/pdf',
      uti:  'com.adobe.pdf',
    );

ygotthilf avatar Sep 02 '21 12:09 ygotthilf