Ionic 3 - File Opener not working on iOS via DevApp

Can anyone help figure out why my app is persisting that FileOpener plugin is not installed when it actually is?

Everytime I try to open a PDF/Image/Docx/XLSX or any other file type I get a notification in the console as per below:

enter image description here

I followed this tutorial here line by line and when I investigate the file structure I can see that the FileOpener plugin is there, see:

enter image description here

enter image description here

In my app.module.ts:

enter image description here

In my user.provider.ts file:

enter image description here

enter image description here

This is my DownloadDocument function:

async DownloadDocument( location: string, name: string, mime: string, message: string = undefined )
  {
    var loading = await this.ShowLoading( message );

    try
    {
      var dir = '';

      if ( this.IsIOS )
      {
        dir = this.file.documentsDirectory;
      }
      else if ( this.IsAndroid )
      {
        dir = this.file.dataDirectory;
      }

      dir = `${dir}${name.replace(/ /g, '')}`;

      const fileTransfer: FileTransferObject = this.transfer.create();

      fileTransfer.download(`${this.APIUrl}/${location}`, dir, true)
                  .then( ( f ) => 
                  {
                    this.fp.open( f.toURL(), mime ).then( () =>
                    {
                      console.log('File is opened')
                    } )
                    .catch(err =>
                    {
                      console.log('Open Error: ' + JSON.stringify( err ));
                    });

                    loading.dismiss();
                  }, ( error ) => 
                  {
                    console.log('Download Error: ' + JSON.stringify( error ));

                    loading.dismiss();
                  } );

    }
    catch( error )
    {
      console.log('General Error: ' + JSON.stringify( error ));
      loading.dismiss();
    }
  }

One thing to note though is that if I use the DocumentViewer plugin, it can open the PDF files. But I would like to use the FileOpener plugin as I intend to open other files other than PDFs.

Can anyone perhaps see what I am doing wrong?

Hi @Morgs009,

The Ionic DevApp doesn’t have all plugins installed, and it seems that cordova-plugin-file-opener2 is not included: https://ionicframework.com/docs/appflow/devapp/#native-cordova-plugin-support

You would have to create your own builds to test this plugin.

Best,
Rodrigo

Thanks for that response I’ve been beating myself up for nothing. I guess everything will work fine if I install the app on the phone.

1 Like