Code Monkey home page Code Monkey logo

Comments (25)

pwlin avatar pwlin commented on July 20, 2024 3

What if you use fileEntry.toURL() in your javascript?

from cordova-plugin-file-opener2.

ronycohen avatar ronycohen commented on July 20, 2024 1

Hi,

Where to get the fileEntry.toURL() ?
I don't understand. Do you have an example with fileEntry.toURL() ?

from cordova-plugin-file-opener2.

vdias38 avatar vdias38 commented on July 20, 2024 1

@ronyrun check code below, and if you need more details about File API I recommend following post: https://www.neontribe.co.uk/cordova-file-plugin-examples/))

window.resolveLocalFileSystemURL(
  path, 
  function (entry) {
    console.log(entry.toURL());
  }, 
  function (err) {
    $log.debug(err);
  }
);

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024 1

@Belheni I am afraid im can't help you with that. Maybe you should start stackoverflow item for that since this is no longer is related to files not opening on ios

from cordova-plugin-file-opener2.

pwlin avatar pwlin commented on July 20, 2024
  • What iOS version and device are you using?
  • Which app have you installed on your iOS device for reading rtf files?
  • Is fullPath a valid path? Does the file really exists there?

from cordova-plugin-file-opener2.

scottdc avatar scottdc commented on July 20, 2024

Sorry it took a while to get back to you on this. So I was in fact having a path issue and have that fixed but now whenever I attempt to open a file the app crashes.

I am testing on iOS7.1 iPhone 4.

Could still be a path issue, I have tried both of these for testing trying to open a PDF with Adobe Reader with the same result:

/Documents/test.pdf

and the full path from root:

/var/mobile/Applications/ . /Documents/noodles.pdf

but am getting a sigabrt at this line:
docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];

from cordova-plugin-file-opener2.

zatch avatar zatch commented on July 20, 2024

I seem to be having the same issue. I do get an "Open with..." dialog if my file path starts with "file://", but the file doesn't open after making a selection. My attempts to use paths without schemas/prefixes have all caused my app to crash like scottdc's.

I'm still learning how to navigate the iOS filesystem, so I could just be using the wrong path, but I figured I'd chime in with my experience so far... Any clues you find toward a solution would be much appreciated -- I'll be sure to post my own findings here, as well.

Update: I tested opening my file with the Mail app, just to see what would happen. All it did was create a new email with the name of my file in the subject line. The subject line was only the name, not the full path. It didn't even add the file as an attachment (which isn't the surprising, but I thought it worth mentioning).

from cordova-plugin-file-opener2.

zatch avatar zatch commented on July 20, 2024

I finally got this working! Some recent changes in Cordova require some extra steps to find the absolute system path for a file. For a File Entry, instead of using toURL() or fullpath, you have to use fileEntry.toNativeURL() to get the full system path. Then you can just use the full system path to open the file in whatever apps can open the file type. :)

from cordova-plugin-file-opener2.

tomraithel avatar tomraithel commented on July 20, 2024

Hey, I have a similar problem here. I´m using the example code but I don´t get any error or success - just nothing happens. This is my code:

cordova.plugins.fileOpener2.open(
    currentFileUrl, // e.g. '/var/mobile/Applications/XXXXXXXXX/Library/files/mypdf.pdf'
    'application/pdf',
    {
        error : function(errorObj) {
            alert('Error status: ' + errorObj.status + ' - Error message: ' + errorObj.message);
        },
        success : function () {
            alert('file opened successfully');
        }
    }
);

I also tried file urls with prefix (file://) from fileEntry.toNativeUrl() like @zatch explained, but nothing happens here.

@zatch can you give me an example with the code that worked for you?

Thanks
Tom

from cordova-plugin-file-opener2.

tomraithel avatar tomraithel commented on July 20, 2024

Uh, I found the problem. In my config.xml I used following preference:

<preference name="iosPersistentFileLocation" value="Library" />

It seems, that this does not work well with the plugin. After removing this line, it worked.

from cordova-plugin-file-opener2.

pwlin avatar pwlin commented on July 20, 2024

@tomraithel Thank you very much, I added this tip as a note to the readme file.

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024

Hey, I have this exact problem. I'm trying to open a pdf file that has been downloaded to my phone.

When execute the following i get a dialog to select the app that should be used:

            cordova.plugins.fileOpener2.open(
                uri,  //cdvfile://localhost/persistent/myPDF.pdf
                'application/pdf',
                {
                    error: function (e) {
                        console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
                    },
                    success: function () {
                        console.log('file opened successfully');
                    }
                });

I've checked the following:
The succes callback is hit
My config.xml doesn't contain iosPersistentFileLocation preference setting

I'm working with apache cordova tools for VS2015 (CLI 5.1.1) and i'm trying to use ibooks to open the pdf.

I recently upgraded to vs2015 after which this problem arose, so i suspect this to be some kind of cordova configuration issue. Can someone help me with this?

Thanks
A2I

from cordova-plugin-file-opener2.

pwlin avatar pwlin commented on July 20, 2024

Try to change plugin's ios source (FileOpener2.m) line:

fileURL = [NSURL URLWithString:path];

to:

fileURL = [NSURL fileURLWithPath:path];

Does that help?

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024

I found the following lines in the FileOpener2.m file:
//fileURL = [NSURL URLWithString:path];
fileURL = [NSURL fileURLWithPath:path];

I tried enabling the first line (URLWithString) but this resulted in a crash of my app.

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024

That solved it. Thank you very much.

from cordova-plugin-file-opener2.

pwlin avatar pwlin commented on July 20, 2024

Ok great. I will add a note to README file about using fileEntry.toURL()

from cordova-plugin-file-opener2.

Belheni avatar Belheni commented on July 20, 2024

@pwlin and @any2info Can you send me a simple and complete version of opening pdf in ios Please? i really tested all the suggestions(changing in fileOpener, fileEntry.toURL(),fileEntry.toNativeURL()..) and the best version is that i have just a successful message of opening pdf without showing it..I really need a solution for that

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024

I use the following helper instance to download and open all sort of files.
I removed some code that applied to our internal netwerk but you should be able use this.

I hope this helps anyone out there struggling with this. If i can be of assistance let me know

download helper example.txt

from cordova-plugin-file-opener2.

Belheni avatar Belheni commented on July 20, 2024

@any2info Thanks for your help but i tested your solution carefully after checking if all plugins exist and nothing is showed.. This is my test really i don't know what's the problem..i will be very thankful if you continue helping me..(if you have a simple project working fine on ios please send it)
TestSolution.txt

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024

@Belheni I looked at the code snippet you added and this seems fine to me and should work.
The only thing i could find that is off is your invocation of openFile(entry.toURL()). Shouldn't this be OpenFile(entry.toURL())?

Also the false and headers parameter can be removed because you probably don't need them. Which should be the case if you are downloading directly from a web uri. In my case i needed them because we are no longer downloading files using uri's.

If this still doesn't solve anything, i would be happy to look at more of your code if needed.

from cordova-plugin-file-opener2.

Belheni avatar Belheni commented on July 20, 2024

@pwlin and @any2info i opened the file in ios but how to detect the click done on the file to close it?or how to detect the closing of the file?
another question is that how to display file in ios on the window inappbrowser and not under the window inappbrowser (default)? Please help me

from cordova-plugin-file-opener2.

any2info avatar any2info commented on July 20, 2024

@Belheni When you want it to open in inappbrowser this should work. Detecting close this maybe

from cordova-plugin-file-opener2.

Belheni avatar Belheni commented on July 20, 2024

@any2info i work with inappbrowser (for the website) and fileopener2.. i open the PDF file using fileopener2 and it works fines.. my question is how to detect the click done on the file to close it? in android file is displayed on the window inappbrowser but in ios file is displayed under the window inappbrowser.. i want to detect close of PDF to show again the window inappbrowser.. i know that my problem is complicated and i wish that you have a solution

from cordova-plugin-file-opener2.

pyroxiano avatar pyroxiano commented on July 20, 2024

The issue I had was with the CGRect passed into presentOpenInMenuFromRect. Changing line 89 to:

CGRect rect = CGRectMake( cont.view.bounds.size.width / 2, 20, 166, 235 );

Worked, and made the dialog appear slightly offset from the screen center.

from cordova-plugin-file-opener2.

juansaa avatar juansaa commented on July 20, 2024

Hola estoy creando mi app online con PhonegapBuild.
Como agrego el plugin en el config.xml?

Hello, I am creating my online app with PhonegapBuild.
How do I add the plugin in the config.xml?

from cordova-plugin-file-opener2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.