pwlin / cordova-plugin-file-opener2

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

Compatibility with android and iOS at the same time. #55

Closed limbenjamin closed 8 years ago

limbenjamin commented 8 years ago

I am deploying the same app on both the iOS and android platform. The app requires opening of locally stored PDF files. Since android does not allow the native PDF application to access the private app storage, I used asset2sd to copy the PDF from the asset folder onto the SD card and used cordovaFileOpener2 to open the file on the SD card. This works fine.

      asset2sd.copyFile({
            asset_file: path,
            destination_file: "myapp/" + path
        },
            function() {}, 
            function(err) { console.log('An error occurred: ' + JSON.stringify(err));}
        );
        $cordovaFileOpener2.open(
            '/sdcard/myapp/' + path,
            'application/pdf'
        ).then(function() {
            console.log('Success');
        }, function(err) {
        console.log('An error occurred: ' + JSON.stringify(err));
        });

My questions is how will this work on iOS given that iOS devices do not have an SD card. Is it possible to have the same code work on both platforms?

pwlin commented 8 years ago

On iOS, people usually use HTML5's FileSystem API and get an entry.toURL() reference and open it from there. Look in other open and closed issues in this repo, There are some examples written by other users.

limbenjamin commented 8 years ago

Thanks, figured that you need an if/else statement and a separate set of code to deal with iOS and android. Not possible to have same code running on both platforms.

$ionicPlatform.ready(function()
    {
        $scope.openPDF= function($path) {
            var path = $path;

            if (ionic.Platform.isAndroid()){

            }else if(ionic.Platform.isIOS()){

            }else{

            }
        };   
    });
pwlin commented 8 years ago

That's great. Good luck!