I'd like to have iOS to open URLs from my domain (e.g. http://martijnthe.nl) with my app whenever the app is installed on the phone, and with Mobile Safari in case it is not.
I read it is possible to create a unique protocol suffix for this and register it in the Info.plist, but Mobile Safari will give an error in case the app is not installed.
What would be a workaround?
One idea:
1) Use http:// URLs that open in any desktop browser and render the service through the browser
2) Check the User-Agent and in case it's Mobile Safari, open a myprotocol:// URL to (attempt) to open the iPhone app and have it open Mobile iTunes to the download of the app in case the attempt fails
Not sure if this will work... suggestions? Thanks!
In iOS9 Apple finally introduced the possibility to register your app to handle certain
http://
URLs: Universal Links.A very rough explanation of how it works:
http://
URLs for certain domains (web urls) in your app.http://
URLs for a setup as explained above and opens the correct app automatically if installed; without going through Safari first...This is the cleanest way to do deep linking on iOS, unfortunately it works only in iOS9 and newer...
Heres a solution.
Setup a boolean sitiation using blur and focus
Bind your link with a jquery click handler that calls something like this.
if the app opens, we'll lose focus on the window and the timer ends. otherwise we get nothing and we load the usual facebook url.
For iOS 6 devices, there is an option: Promoting Apps with Smart App Banners
I found that the selected answer works for the browser apps but I was having issues with the code working in non browser apps that implement a
UIWebView
.The problem for me was a user on the Twitter app would click a link that would take them to my site through a
UIWebView
in the Twitter app. Then when they clicked a button from my site Twitter tries to be fancy and only complete thewindow.location
if the site is reachable. So what happens is aUIAlertView
pops up saying are you sure you want to continue and then immediately redirects to the App Store without a second popup.My solution involves iframes. This avoids the
UIAlertView
being presented allowing for a simple and elegant user experience.jQuery
Javascript
EDIT:
Add position absolute to the iframe so when inserted there isn't a random bit of whitespace at the bottom of the page.
Also it's important to note that I have not found a need for this approach with Android. Using
window.location.href
should work fine.In seeking to fix the problem of pop-up, I discovered that Apple had a way around this concern.
Indeed, when you click on this link, if you installed the application, it is rerouted to it; otherwise, you will be redirected to the webpage, without any pop-up.
It's quite possible to do this in JavaScript as long as your fallback is another applink. Building on Nathan's suggestion:
Check out a live demo here.