Possible Duplicate:
iPhone Mobile Safari File System Access
I want to open a locally saved image in Safari through my app.
When my app loads, I place an image in “/Users/username/Pictures/xxx.jpg”. If I open Safari directly and enter “file:///Users/username/Pictures/xxx.jpg” or “file://localhost/Users/username/Pictures/xxx.jpg”, the image opens in the browser.
But if I try to open Safari through my app, neither Safari, nor the image opens. Following is the code I use to open Safari through my app.
NSString *str = [NSString stringWithFormat:@"file:///Users/username/Pictures/xxx.jpg"];
str = [str stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:str];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
A point worth mentioning is that if I open an HTTP URL, say http://www.google.com, the app opens Safari with the URL specified.
I’m trying this on Simulator and have not saved the image in the my apps folder just to make sure that the image is not sandboxed. Even if I place the image in my apps folder, I get the failure message.
Please note: I’m not using a UIWebView as it will defeat the Business Requirement.
You can’t access Local files by opening the Safari Browser because it is sandboxed and can not access files included in your App Bundle or Directory. You may need to change see if you can change the business requirement and use a UIWebView