iOS Universal Links are not opening in-app
There is apparently an error in the documentation for making the association file for Universal Links.
Where it says:
The value of the appID key is the app’s team ID and the bundle ID
it should say
The value of the appID key is the app’s Prefix and the bundle ID
For most apps, it seems that the Team ID and app prefixes are the same, but if your app has been in the store for many years, these values can be different.
To find this value, open the Member Center on https://developer.apple.com and look at "Certificates, Identifiers & Profiles", click "Identifiers", then "App IDs" in the table under "Identifiers". Find your app, and use the Prefix value and Bundle ID there to create your AppID for the association file.
There are a lot of ways this can go wrong. Two points caused me trouble:
In Xcode, when you add the Associated Domains entitlement, each entry needs to start with
applinks:
and then your domain name. E.g.applinks:www.apple.com
.Though Xcode created an entitlements file for me, it did not include in my build: I had to click that box manually.
And yes, after doing that, it wasn't necessary to sign the apple-app-site-association
file: it is just plain text, and it works, as long as it's served over HTTPS. (You'll still need to sign it if you're supporting iOS 8, though.)
To help debugging this issue, search for "swcd" in your device's console output when installing your app to see if registering your universal link worked or failed.
- Use an actual device, not the simulator.
- Delete the app from you device.
- Connect the device to your computer, and view the device's console output in xcode. (window -> devices -> [your device] -> open console). Keep this window open.
- Install your app and let it launch.
- Filter the console output to "swcd". If it's sucessful you will see something like the folowing screenshot. If it fails you'll see something else. If you don't see anything then you messed something fundamental like adding the Associated Domains entitlement.
There are a few possible issues.
Try pasting your domain into this link validator and make sure there are no issues: https://limitless-sierra-4673.herokuapp.com/ (credit to ShortStuffSushi -- see repo)
iOS logs an error message in the system logs if you don't have TLS set up properly on the domain specified in your entitlements. It's buried in the OS logs, not application logs. The error message will look like
Sep 21 14:27:01 Derricks-iPhone swcd[2044] <Notice>: 2015-09-21 02:27:01.878907 PM [SWC] ### Rejecting URL 'https://examplecustomdomain.com/apple-app-site-association' for auth method 'NSURLAuthenticationMethodServerTrust': -6754/0xFFFFE59E kAuthenticationErr
. Error message pulled from here, quick (incomplete) instructions on using CloudFlare for TLS here.In my personal testing, clicking/typing in a link in Safari has never once opened the app directly. Clicking from other apps (iMessage, Mail, Slack, etc.) has worked. Others have reported that clicking links in Google search results have opened the app directly.
Note that if a Universal Link succeeds in opening your app and then you click through to Safari (by tapping your site in the top right corner of the nav bar in app), then iOS stops opening the app when you visit that URL. Then in Safari, you can pull down to reveal a banner at the top of the page with "Open". I wasted a lot of time on this. Note that clicking through to the site => disabling UL seems path specific, based on the paths you specify in the apple-app-site-assocation file. So if you have separate routes,
yoursite.com/a/*
andyoursite.com/b/*
, if you clickyoursite.com/a/*
and it opens your app directly, you then have the option in the top right corner of the app to click through toyoursite.com/a/*
. If you do that, subsequent visits toyoursite.com/a/*
will open in browser, not app. However,yoursite.com/b/*
should be unaffected and still open your app directly.
Let me know if you discover what the issue is. I'm personally very curious about how Universal Links work and what edge cases exist. Good luck.