I’ve read several posts on here on how to launch Safari from within an app which all say to use UIApplication:OpenURL: However this is not working for me.
I have a .html page which has been downloaded and is stored in my application’s sandbox.
I can launch this page in a UIWebView, but cannot launch it in, with the following code nothing happens.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:firstPageFullPath];
[[UIApplication sharedApplication] openURL:[requestObj URL]];
The path is of the form file://…./page1.html, and as I mentioned, if I pass the requestObj to a UIWebView it will load successfully.
Any ideas why its not working, can Safari only be launched from an app with a non-local file?
Safari behaves pretty much like your own sandboxed app – i.e. it can’t access files outside of its own sandbox. So it can’t access the file you are referring it to with the file URL because that file resides in your app’s sandbox, not Safari’s. You should pass a remote URL to Safari – by putting your html on a web server somewhere. If this is not possible/practical for your app, then you’ll need to continue using a
UIWebViewinside your app – as you have already found this is able to access the local html file. Implement any additional controls you need (forward, backward etc) to mimic the behaviour of Safari.