Ios9: Try to Open App via Scheme If Possible, or Redirect to App Store Otherwise

iOS: opening app with custom URL if installed, itunes otherwise

To be honest, this is kind of a pain to implement on your own. After you've detected the iOS user agent, you could implement a JavaScript redirection on your server something like this:

setTimeout(function() {
window.location = "https://itunes.apple.com/path/to/your/app/";
}, 25);

// If "yourapp://" is registered, the user will see a dialog
// asking if want to open your app. If they agree, your app will
// launch immediately and the timer won't fire.
// If not installed, you'll get an ugly "Cannot Open Page"
// dialogue and the App Store will launch when the timer expires.

window.location = "yourapp://";

Obviously this isn't an ideal solution and it has a ton of nasty edge cases, most notably the 'Cannot Open Page" error users will see before being redirected to the App Store if they don't have your app installed. Until recently, it was possible to get around this in a reasonably user-friendly way by using a more nuanced version of this script. Sadly, Apple intentionally broke that with the iOS 9.2 update.

You could also enable Universal Links. Apple knows this is an annoying problem and is trying to help. Universal Links let you use a normal URL to a page on your website (which could be a simple redirection to the App Store without the custom URL trigger that causes the 'Cannot Open Page' error), which is intercepted by your phone and sent directly into your app if installed. Unfortunately Universal Links only work in iOS 9+, and don't work yet when opened inside a lot of apps.

The best solution is a combination of the above methods: Universal Links and Applinks everywhere they are supported, and intelligent JavaScript redirections as a fallback. This is quite a lot to handle, so the best option might be a free service like Branch.io (full disclosure: I work with the team) to take care of all the technical aspects.

iOS 9 safari iframe src with custom url scheme not working

The previous answer is a partial implementation of Universal Links that is missing critical details and doesn't include a fallback to the App Store.

First, you can no longer set iframe src in order to trigger a URI scheme. You've correctly identified that issue. As you noted, you can, however, still set window.location = 'custom-protocol://my-app';. So if you know that a user has your app because you've previously opened their app from the browser and have a cookie stored that can be looked up on your backend, you can still safely fire custom-protocol://.

Second, you can detect the user agent string using navigator.userAgent. Pre-iOS 9 you can still use the iframe to fire a URI scheme, then fallback after a timeout. On iOS 9, you can choose whether to fire the URI scheme or not based on cookies, then take the user to the App Store. I work on this at Branch and making use of cookies to recall whether a user likely has the app is something we've implemented. Feel free to reach out if you have more questions about that, or make use of our solution directly.


Implementing Universal Links is not quite as simple as the other answer describes. In reality, there is considerably more complexity. Here's a complete list of steps (I've helped several apps integrate in recent weeks using these steps):

1. Configure your app to register approved domains

i. Registered your app at developer.apple.com if you haven't

ii. Enable ‘Associated Domains’ on your app identifier on developer.apple.com

iii. Enable ‘Associated Domain’ on in your Xcode project

entitlements

iv. Add the proper domain entitlement, applinks:yourdomain.com, in your app

applinks

2. Configure your website to host the ‘apple-app-site-association’ file

i. Buy a domain name or pick from your existing

ii. Acquire SSL certification for the domain name (you can use CloudFlare for this!)

iii. Create structured ‘apple-app-site-association’ JSON file

{
"applinks": {
"apps": [ ],
"details": {
"TEAM-IDENTIFIER.YOUR.BUNDLE.IDENTIFIER": {
"paths": [
"*"
]
}
}
}
}

iv. Sign the JSON file with the SSL certification


v. Configure the file server

The apple-app-site-association file:
- must be sent with the header ‘application/pkcs7-mime’
- must be sent from the endpoint youdomain.com/apple-app-site-association
- must return a 200 http code.

Example Express+Node:

var aasa = fs.readFileSync(__dirname + '/static/apple-app-site-association');
app.get('/apple-app-site-association', function(req, res, next) {
res.set('Content-Type', 'application/pkcs7-mime');
res.status(200).send(aasa);
});

credit: borrowed liberally from this blog post

Opening installed app using URL Scheme is not working

I don't see a problem on your side, seems like everything is set correctly.
However, regarding iOS 9, other users reported this problem with iframe. Make sure the things are setup correctly on server side. Check these 2 links:

iOS 9 iFrame Problem 1

iOS 9 iFrame Problem 2

Can't open my app from facebook in-app browser iOS 9

Edit

There is an active bug report open for this https://developers.facebook.com/bugs/802238099898150/


As far as I understand, iOS 9 changed the way apps can interact with other Apps using custom URL schemes (Read more here). The basic idea is that Facebook can no longer intelligently open other apps using a custom scheme as they have to register all the schemes they support inside the App plist.

I have tested AppLinks with YouTube, 9GAG, Flipboard and IMdB and none of them work as they used to. The advertised behaviour (found here) is that your App will be opened if your link contains the relevant html app links tags.

Now the only way to open your app is to tap "Share" in the Facebook browser of the page you want to open, and you should see a "Open in 9GAG" line item that will open your app.

How to open ios app using url?

I handled it via my server side code:

if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("com.myapp://");
setTimeout(function() {
if (!document.webkitHidden) {
location.replace("https://itunes.apple.com/app/xxxxxxxx");
}
}, 25);}
else if ((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/Android/i))) {
location.replace("https://play.google.com/store/apps/details?id=packagename&hl=en");}
else {
location.replace("http://www.example.com");}

I put this in my www.mysite.com/download page & share this url via campaigns.



Related Topics



Leave a reply



Submit