I'm trying to create an environment to enable the opening of an iPhone app from an email. If I use Facebook's hosted service for an appLink (Facebook AppLink Hosting API), I can successfully open the app as long as I click the link it produces from within the Facebook mobile app. But if I try to click that same link from within another mobile app (e.g. Notes or Mail), it only redirects to Facebook, but not to my app. Furthermore, the Facebook AppLink Hosting API only lets you create a link for a single app. I want to be able to automatically open either my paid version of the app or the free version of the app (in that order) depending on which app the user has on their mobile device.
So, I followed the description found at (applinks.org) of how to set up the meta tags on my own server to perform the task of opening an AppLink. So, I have a web page with the following html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>MyApp</title>
<meta property="al:iphone:url" content="myAppLinkScheme://Home">
<meta property="al:iphone:app_name" content="MyApp">
<meta property="al:iphone:app_store_id" content="471147787">
<meta property="al:iphone:url" content="myAppLinkLiteScheme://Home">
<meta property="al:iphone:app_name" content="MyApp Lite">
<meta property="al:iphone:app_store_id" content="518829102">
<meta property="al:ipad:url" content="myAppLinkLiteScheme://Home">
<meta property="al:ipad:app_name" content="MyApp Lite">
<meta property="al:ipad:app_store_id" content="518829102">
<meta property="al:web:should_fallback" content="false">
</head>
<body>Redirecting...</body>
</html>
Then I created an appLink using Facebook's tool for hosting an AppLink. Using their Open Graph Object Debugger, I was able to scrape the content of the AppLink I created with their tool. The Facebook meta tags were very similar to my meta tags, but had a couple differences. As I mentioned before, the first difference is that you can only have one app specified using the Facebook tool, so there is only one iPhone url, app_name, and app_store_id meta tags. The other two differences are the following tags [I replaced my app_id in the following tags with ....]:
<meta property="fb:app_id" content="28...........64">
<meta http-equiv="refresh" content="0;url=https://apps.facebook.com/28...........64/?fb_source=mobile">
There is obviously a redirect occurring with the "refresh" meta tag to apps.facebook.com. I don't know what goes on there, but even if I put all of these tags in my web page head tags, the result is the same. If you click on the link from a mobile app such as Mail or Notes, you will only open my web page. A redirect does not occur to my app or to Facebook.
Note that I also have added the required scheme info to each of my app's info.plists and appDelegates. Namely, in the URL types of my info.plist, I added the identifier of com.myApp.myAppLinkScheme and a scheme of myAppLinkScheme. A similar addition was made for the lite version of info.plist. Also I added the necessary changes to my appDelegate for both the paid and free version of the app:
-(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if ([[url scheme] isEqualToString:@"myAppLinkScheme"]) {
return YES;
}
...
}
So, I am obviously missing something. What additional implementation is required to set up my server so that when a user clicks on a link that points to my server from within the Mail app of their iPhone, they are redirected to my app?
Those <meta>
tags are respected by apps (like Facebook) that have implemented to Applinks protocol and know to look for them. Other apps like Mail and Safari totally ignore them, opening the fallback URL instead.
When you're using the Mobile Hosting API, that fallback URL is registered to open the Facebook app. Unfortunately Facebook doesn't forward you through to your own app afterwards.
When you're using your own server, the fallback is simply a URL on your website...which isn't registered to anything. Yet.
To get around this, you need to perform the link-to-app redirection in some way that doesn't depend on Facebook. There are a few options:
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 if they don't have your app installed. Until recently, it was possible to get around this in a reasonably user-friendly way by intelligently redirecting to the App Store with a more nuanced version of this script. Sadly, Apple intentionally broke that with the iOS 9.2 update.
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.