Thanks to thelaws I've fixed the exhibiting problem in the device. But I still need to fix the images issue. Gotta download them along with the HTML and exhibit as well, any hints?
EDIT:
-FIXED Actually I am using this code, i got from Anne in another thread. It works (not showing images nor anything else than html) on iOS Simulator but fails to exhibit anything (not even console errors) when i try to run in my device, what's the problem?
// Determile cache file path
NSString *path = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", path, #"index.html"];
// Download and write to file
NSURL *url = [NSURL URLWithString:#"http://www.google.nl"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
// Load file in UIWebView
[web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
Fixed the path to:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
This is because you can't write to the bundle on a Device, although it works on the simulator.
Please see Technical Q&A QA1662 for more details straight from Apple
Related
I want to download a PDF file then open it in a webView. I searched about that then I found this issu. The accepted answer describes how to download and display the file. When I test it, I can not find the file in the Documents because it's stored inside my app. Also I don't think that the file is saved because the pdf is never shown in the webView even if I pass the filePath to be loaded. This is the code of the answer:
// Get the PDF Data from the url in a NSData Object
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[
NSURL URLWithString:#"http://www.example.com/info.pdf"]];
// Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[
[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]
stringByAppendingPathComponent:#"Documents"
]];
NSString *filePath = [resourceDocPath
stringByAppendingPathComponent:#"myPDF.pdf"];
[pdfData writeToFile:filePath atomically:YES];
// Now create Request for the file that was saved in your documents folder
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView setUserInteractionEnabled:YES];
[webView setDelegate:self];
[webView loadRequest:requestObj];
And this is what I see in the log:
libMobileGestalt MobileGestaltSupport.m:153: pid 2828 (my_app) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled
2017-08-01 10:29:06.882562+0100 my_app[2828:1334057] libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see <rdar://problem/11744455>)
What is the problem with what I did? And how can I put the downloaded file in the Documents app of my iPhone in order to be checked whenever the user want like any other PDF?
Sandbox path Error
NSString *resourceDocPath = [[NSString alloc] initWithString:[
[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]
stringByAppendingPathComponent:#"Documents"
]];
Please use your sandbox path instead of bundle path.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
Is there an ability to load files like documents, articles from server and store them in application local storage using Filemanager? And how then users can read these files? Do they have access to that folder?
Follow these steps for downloading and saving file in NSDocumentDirectory
// Determine local file path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:#"%#/%#", [paths objectAtIndex:0],#"fileName.doc"]; //it could be any file type
// Download and write to file
NSURL *url = [NSURL URLWithString:#"http://www.filePathFromServerLocation.com"];
//and write to file
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
This way your file will be save at filePath and u can use it in future whatever the way u like.
Opening a file in iOS:
Using a webview
NSString *path = [[NSBundle mainBundle] pathForResource:#"document" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
using a UIDocumentInteractionController.
Have a look at this Apple sample code for ZoomingPDFViewer
Hi in my application i have option of downloading a pdf file i have searched for that i got the code i have used its working fine in my mac i can see the downloaded pdf file. But the problem is if i download the same pdf in device where i can find the downloaded pdf file in device.
This is my code which i have used to download the pdf file.
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://jesusredeems.com/mag/pdf/JRE-2014-03.pdf"]]; //Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:#"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:#"11011.pdf"]; [pdfData writeToFile:filePath atomically:YES]; NSLog(#"%#",filePath);
If i print the filepath I'm getting like this.
/var/mobile/Applications/353C27AD-1E64-41CA-A429-16C2A20C8606/Documents/11011.pdf
In my mac i can see the downloaded file in that path but in my Ipad where i can see the downloaded pdf file please anyone tell where i have to find it.
Thanks.
Most likely your saving part is correct but try this anyways.
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://jesusredeems.com/mag/pdf/JRE-2014-03.pdf"]];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSString *destPath = [documentsPath stringByAppendingPathComponent:#"11011.pdf"];
[pdfData writeToFile:destPath atomically:YES];
And do this to retrieve it.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSString* dataFile = [documentsPath stringByAppendingPathComponent:#"11011.pdf"];
NSData *pdfData3 = [NSData dataWithContentsOfFile:dataFile];
i have a sqlite file on a server
i want to connect to that server via objective-c on just after user successfully login to the application. then download the file to the bundle of app and then use it in other views.
First i want to ask is it possbile? if it is possible is there any tutorial or example for this?
Yes it is possible.
There are many ways to download files from a server this is one of them:
NSString *stringURL = #"http://www.somewhere.com/thefile.sqlite";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename.sqlite"];
[urlData writeToFile:filePath atomically:YES];
}
Here is a tutorial for SQLite:
SQLite Tutorial
Yes its possible. The file would can be stored in Application Document / Library directory.
The same can be achieved by using NSURLConnection.
A sample tutorial explaining NSURLConnection tutorial-how-to-use-ios-nsurlconnection-by-example
Hope this helps.
Hi I have my iPhone app which will be run on a jailbroken iPhone and I want to download a file from the web and place it in another apps directory.
I am new to iOS development and have successfully downloaded the file and placed it in the Documents folder but how do I search for the UID of the app and place it in the library folder of another app? Keeping in mind this is on JB iPhone and have access to the filesystem.
Here is what I have so far.
NSString *stringURL = #"http://testfile.plist";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#%#", documentsDirectory,#"/testfile.plist"];
[urlData writeToFile:filePath atomically:YES];
Thanks
You can do documentation interaction controller make sure you develop custom url scheme and you should be able to pass around with user consent .