I have a file, which i want to open in safari (or call it view in safari). I add this file to my bundle resources.
and do the following:
NSString *path = [[NSBundle mainBundle] pathForResource:@"tryFile.txt" ofType:nil inDirectory:nil];
NSURL *url = [NSURL fileURLWithPath: path];
NSLog(@"path: %@ \n url:%@ \n can open url:%d",path,url,[[UIApplication sharedApplication] canOpenURL:url]);
BOOL didGo = [[UIApplication sharedApplication] openURL:url];
NSLog(@"didgo?: %d",didGo);
Of course, as the sandboxed environment says, I am not able to open the file ins safari. It says, canOpenURL
as yes
but then didGo
is NO
.
How can I do this without setting up a local server. Please suggest. Should I keep the data stored in a variable and then open an html page with that data...or what?
EDIT: These are the logs:
path: /var/mobile/Applications/C78C7CD8-22C7-468A-AA5D-AF22C6042378/TryApp.app/tryFile.txt
url:file://localhost/var/mobile/Applications/C78C7CD8-22C7-468A-AA5D-AF22C6042378/TryApp.app/tryFile.txt
can open url:1
didgo?: 0
PLEASE NOTE opening the file in a webview is not an option. The requirement wants it to be opened in safari. And anyways, this example is of a text file...the filethat may be opened can be anything, and webview does not support all file types.