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 UIWebView inside 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.
I'm going to guess that this is meant to happen for file URLs. If you use UIWebView, that browser instance uses your application's sandbox (e.g. The cookies available for that browser instance is independent with the Safari app's cookies). If you use Safari, then you're out of your sandbox, and Bad Things™ can happen if Apple allows it to be used like a file-explorer.
Related
I have an app that logs you in via opening safari and redirecting you back to the app - however on "Log out" I need to open safari in order to log you out - is there a way to do this in the background instead?
For Log in:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[DataService loginURL]]];
However, I would like to not have to do the same for Logout - and simply get safari to run in the background or something similar. The problem is that the cookies are saved, and I need to get rid of them. Can I get safari to open a website without having to open Safari through the application?
Can you open Safari in the background? I'm pretty certain that the answer to that is no. In any case, if your main concern is to delete the cookies then you may not get the chance - the user could just kill the app, and the cookies would sit in Safari.
Is it an option to use a UIWebView or WKWebView to perform authentication? So rather than taking them off to Safari, the user would see the browser content actually inside the app.
That might improve the user experience, and you'd get a lot more control. For example, you could point the web view to your log out url when the time came for it. That might save you some cookie hassles too.
Besides which, I think openURL: is now deprecated because it was involved in some shenanigans.
I am making on Xcode 6.1.1 and application and wanted to have a link that takes you to https://www.instagram.com/naturee/
I added this:
NSURL *instagramURL = [NSURL URLWithString:#"instagram://user?username=naturee"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
form
https://www.instagram.com/developer/mobile-sharing/iphone-hooks/
But it takes me to Instagram application but not a username!
Does anyone know how??
To understand Universal Links, it’s important to first understand deep links.
Deep links are nothing more than the ability to open up an application to a specific piece of app content. It’s akin to linking to a page other than a homepage on a website.
In order to deep link into an app, traditionally a developer had to register a protocol (i.e. instagram:// , twitter:// , facebook:// ) with the operating system when an app is installed. Subsequently, when an incoming request is received on the device to a registered protocol, the operating system launches the associated application, letting it handle the request (link).
This works well enough; however, if a developer has a website mirroring its app content it results in having to effectively manage, maintain, and synchronize two sets of URL schemes, one for the web and one for the app.
Universal Links try to solve this problem by enabling an app to handle incoming https:// requests (regular web requests).
On iOS 9, a user may navigate or click a link to a webpage and if that website is setup to handle Universal Links (and the app is installed on the device), the operating system will intercept the request (without opening Safari if not already open) and pass the request to the associated application.
Universal Links are an easy way to intelligently route web traffic to an application if available. It enables developers to make the app the default place to send web traffic on iOS, using the web as the backup destination if the app isn’t installed.
quoted from this site
You can use Support Universal Links in your application on iOS9.
There is more information on this link
Your code will work if you change ur NSURL by :
NSURL *instagramURL = [NSURL URLWithString:#"https://www.instagram.com/naturee/"];
If you still want to use URL Scheme, there is something wrong with your actual one :#"instagram://user?username=naturee". You can check it by opening safari on your device and past this url scheme. it won't open instagram's naturee's profile.
I'm using an iPhone App that has some important information on it, but I also figured out that it uses a webview. And I'm not sure if it's safe; like; is it over https? What URL is being called?
Is there a way you can find out what Website is being called in the webview? Like you can do inspect element when using Safari from OSX with usb-connected iPhone.
UIWebview works for any url you call it with. If your site is https, the communication will be encrypted. Not all requests on UIWebView are not https. You can't inspect element from iPhone/iPad/Simulator. You can do it in web in the mobile view (by using useragent).
I am developing an app using Appcelerators Titanium. The app consists of a webview. The webview shows i local page, iframe.html, and this iframe's src is pointed to a remote page.
However, this doesn't work out as i expected since it doesn't seem like the remote page can't store cookies when wrapped in an iframe. It works great on desktop and other devices. This seems to be an issue exclusive to iOS. I need the iframe, and i need cookies. What can i do to solve this?
I am attempting to open mobile safari from an iOS app to open an offline HTML5 app with openURL:
NSString *urlString = [NSString stringWithFormat:#"http://localhost:8080/blargh.html"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
blargh.html has an HTML5 manifest:
That manifest contains the html file:
CACHE MANIFEST
blargh.html
This all works as expected, when I open the URL from my iOS app, it is cached properly and works offline. However, it doesn't cache properly if I include dynamic cgi params:
NSString *urlString = [NSString stringWithFormat:#"http://localhost:8080/blargh.html?q=p"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
This basically means that I can't open an offline HTML5 app from an iOS app and pass it params and have it cache properly. I need to open the app in mobile safari and not a webview for reasons that are beyond this post. As far as I am aware there is no way to send post params through openURL. I would have hoped that mobile safari's caching system would have been smart enough to ignore cgi params.
Any suggestions?
Query params muck up the app cache because it's intended for static content. The usual approach is to load a static page and then use JavaScript to populate it dynamically, caching any data in DOM Storage so that you can use it offline too.
However, if you just need to cache the one file and your server supports routing or URL re-writing, then you can take advantage of the fact that the page that contains the link to the appcache file is always cached, so doesn't itself have to be listed in the manifest.
Re-write your URL from this:
http://localhost:8080/blargh.html?q=p
To:
http://localhost:8080/blargh.html/q/p