0
votes

Background

I am building an Ionic/Cordova application. The primary platform I am targeting is IOS, but the application may ultimately be cross platform. I would like to launch download and open a PDF on the device using an installed PDF viewer. I do not want the user to be prompted to select which application to use when opening the file.

Environment

  • Visual Studio 2015 Update 2
  • Cordova 6.1.1
  • TACO Updated 8.1
  • Node 6.0.0
  • iPad Mini 2 running iOS 9.2 (13C75)
  • iPad Air 2 running 9.2.1 (13D15)
  • Adobe Acrobat Reader

Issue Description

When I attempt to open a PDF on an iPad (either the iPad Mini, or Air 2) a small dialog box appears with a list of options in the form of application icons. The options include 'Message', 'Mail', 'Notes' etc. along with 'Copy to Adobe Acrobat'. Choosing the 'Copy to Adobe Acrobat' option will launch my PDF in Adobe Acrobat.

I would like the content to launch with the appropriate application without having to select one from a list. I always want my PDF's to launch in Adobe Acrobat without prompting the user to select an action.

When the same code is executed on Android the PDF is opened using the default PDF viewer as expected.

Relevant Code Sample

Here is the code that is being executed to download the file and to store it on the device along with the call to open the file. In the case of a pdf, mime is set to 'application/pdf'

$cordovaFileTransfer.download(category.assetPath, targetPath, {}, true)
                .then(function (result) {
                    result.file(function (file) {
                        var localFile = file.localURL;
                        resolveLocalFileSystemURL(localFile, function (entry) {
                            var nativePath = entry.toNativeURL();
                            if (ionic.Platform.isAndroid()) {
                                nativePath = decodeURIComponent(entry.toURL());
                            }

                            // Open in another app, will fail if app doesn't exist that can open the mime type
                            $cordovaFileOpener2.open(nativePath, mime).then(function () {
                                // Success!
                            }, function (err) {
                                // Error!
                            });
                        }, function (error) {
                            //handle error here
                        });
                    }, function (error) {
                        // handle error here 
                    });
                }, function (err) {
                    // Error
                }, function (progress) {
                    $timeout(function () {
                        category.downloadProgress = progress.loaded / progress.total;
                    });
                });
        }

The Question

Is it possible to open content from my Ionic/Cordova mobile application on an iOS tablet using a default application without the user being prompted every time to select the application?

How do I get the FileOpener2 plugin to open a PDF on an iPad with Adobe Reader installed without asking the user to select the application/action first every time the PDF is selected?

1
as far as I know, its not possible in iOS to default it to a particular application using file opener plugin and have tried it personally. In your case, its better to use inappbrowser pluginGandhi
I believe Gandhi is correct. If you add your comment as an answer I will accept it. This is native behavior on iOS due to sandboxing. Even microsoft onedrive uses the same window to launch microsoft apps such as excel etc.Zoop
Have posted the answer zoop. Accept the same to help others. Happy coding. Cheers.Gandhi
I believe you hav give an upvote but not accepted the answer as I don't see the tick markGandhi

1 Answers

2
votes

As far as I know, its not possible in iOS to default it to a particular application using file opener plugin and have tried it personally. In your case, its better to use inappbrowser plugin as PDF viewing is supported built in by iOS webview.