I'm using Xcode 5.1.1 and Cordova 4.0.0
To the functionality by the app:
In my app I call a Webservice in JavaScript, which returns a PDF-file. This PDF-file is then stored by the app under following path: "cdvfile://localhost/persistent/appname/pdffilename.pdf" (I've already checked if the path is correct by doing console.log() in JavaScript ).
Little hint: I'm using a JavasScript-Object of the class "FileTransfer". After I've updated the "file"-plugin for cordova, the functionality of handling and storing files changed and I had to update the way of handling files in my app, described under the following link: http://cordova.apache.org/news/2014/02/10/plugins-release.html
The version of the plugin now is:
org.apache.cordova.file 1.3.2-dev "File"
After I've stored the file under "cdvfile://localhost/persistent/appname/pdffilename.pdf" I call a Native PDF-Handling-Plugin which is written in Objective-C by calling the JavaScript-function "cordova.exec".
cordova.exec(null, null, "PDFNet", "showLocallyStoredPDF",[encodeURI(pathToFile), encodeURI(fileName)]);
As you can see, I'm passing two parameters to the showLocallyStoredPDF-function. The first parameter is the path to the actual PDF-file:
"cdvfile://localhost/persistent/appname"
And the second parameter contains the name of the PDF-file:
"pdffilename.pdf".
Inside the "showLocallyStoredPDF"-function I get the passed parameters by doing the following:
NSString* pathToFile = (NSString*)[command.arguments objectAtIndex:0];
NSString* fileName = (NSString*)[command.arguments objectAtIndex:1];
After doing
NSLog(pathToFile);
NSLog(fileName);
the XCode-console shows the correct values:
cdvfile://localhost/persistent/appname/
and
pdffilename.pdf
To open the PDF documents inside that native plugin, you have to do the following (as described in this tutorial: http://blog.pdftron.com/2013/07/19/getting-started-on-ios/):
PTPDFDoc* docToOpen = [[PTPDFDoc alloc] initWithFilepath:fullPath];
I tried to define the "fullPath"-variable static like that (because I know the file "pdffilename.pdf" is stored in "cdvfile://localhost/persistent/appname"):
NSString* fullPath = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat:@"cdvfile://localhost/persistent/appname/pdffilename"] ofType:@"pdf"];
but that didn't work. The XCode-console throws an exception:
* Terminating app due to uncaught exception 'NullPointerException', reason: 'null std::string' * First throw call stack: (0x182c87100 0x18f5401fc 0x10029529c 0x100154034 0x10012d9c0 0x1000ccba4 0x1000cc47c 0x1000cbfdc 0x1000cc214 0x1000cc118 0x1838085cc 0x182c477f4 0x182c46b50 0x182c44de8 0x182b85dd0 0x188815c0c 0x185cb6fc4 0x1000e544c 0x18fb33aa0) libc++abi.dylib: terminating with uncaught exception of type NSException
So I tried to do that:
NSString* fullPath = [[NSBundle mainBundle] pathForResource:@"pdffilename" ofType:@"pdf" inDirectory:@"cdvfile://localhost/persistent/appname"];
but it throws the same exception as above.
Does anybody here have an idea how I can obtain files (which are stored under "cdvfile://localhost/persistent/appname/filename.pdf") in Objective-C?
Thanks in advance to everybody!