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
Related
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 am working with a custom iOS iPad application.
Every application in iOS can be treated as a web server (so to speak).
All over the net, I see that you can "call" Twitter from another app by using a hyperlink including "twitter://". What about other applications? Where is a repository from which to learn this information?
I want to use Safari and Adobe. Do I use safari://, or acrobat://?
Note: If you reply to this question by using any Code other than HTML or plain hyperlinks, you are completely wasting your time, my time, and anyone's time who will read your answer at a later date. Many people have asked this question only to get a whole bunch of great answers from smart people...only that the answers do not AT ALL match the question.
To open a web page in Safari, just use the openURL: function:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
With Adobe, things are a little more complicated. I couldn't find a public URL scheme, so I downloaded the Adobe Reader app and looked at its Info.plist file. I found its URL scheme to be com.adobe.Adobe-Reader.
// I'm using a local file here, but it should also work with any remote PDF files
NSString *path = [[NSBundle mainBundle] pathForResource:#"SomeFile" ofType:#"pdf"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"com.adobe.Adobe-Reader://%#", path]];
// Check to see if the user has Adobe Reader installed
if ([[UIApplication sharedApplication] canOpenURL:url]) {
// Reader is installed, open the PDF
[[UIApplication sharedApplication] openURL:url];
}
So your "plain hyperlinks" are http://www.google.com and com.adobe.Adobe-Reader://.
On my application I have to go from one application to another through json data.
If the app is available on app store then user wont get any issue but if app is not available on app store and if we are trying to call the json then it dosen't open the json url which I am getting through previous app.
Is there any way to open that app which is NOT available on app store but available through build or anything?
You can open any app using a custom URL scheme. Ask the app makers to add one and adjust the JSON and launcher accordingly.
Yes, you can open another application from your Application. but you need know the URlscheme for that Application.,
For Example i want to open an URl with some links, Then i will Use the following to open that URL From my application.,
NSURL *myURL = [NSURL URLWithString:#"http://www.google.co.in/"];
[[UIApplication sharedApplication] openURL:myURL];
if you want to know more about the URLScheme Refer the Following Link.,
It may help you
https://developer.apple.com/library/IOs/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW18
we have an iPhone application that can share to Facebook but we have a problem with one of our share links (all the links use the same code).
The code is the following:
NSString *fullUrl = [NSString stringWithFormat:#"http://www.facebook.com/sharer.php?u=%#",
[campaignToShare.shareurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fullUrl]];
When we call the openURL method with the parameter: http://www.facebook.com/sharer.php?u=http://open.mikz.com/upvudd
we get it translated on safari (also opera) to the following url:
http://m.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fopen.mikz.com%2Fupvudd&_rdr
which does not work, however if use the url before the redirect to m.facebook (on the computer) then it works.
Is the code that we have written wrong or have we found a bug for iOS + m.facebook.com?
Obs: It works for all the other links that we have, the only differens on those links are that they have a different code (instead of upvudd).
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.