I've found two options to open my app from a Safari web page: a custom URL scheme created in my app project's Info.plist
or Apple's Universal Linking. Obviously the custom URL scheme is the easiest one to set up, but the problem I'm having with this is that Safari shows a confirmation window asking "Open myapp
?" first and the user has to tap OK before the app actually opens. I want my app to open automatically as the scheme is opened, and I'm being told the only way to do this is through Universal Linking (please correct me if this is not true). If this is true, however, I would like to know if it's possible in any way to put the required apple-app-site-association
file on a http://
domain instead of https://
? According the official Apple documentation the format of a correct Universal Link starts explicitly with https://
but my domain name can't be loaded on https://
without redirecting a few times and that messes up the web services I've written to execute other tasks in my app. The two main questions I'm left with after this issue:
1) Is it really impossible to work around the confirmation prompt using a custom URL scheme (myscheme://
)? If it's not impossible, how can I do this?
2) If I have to use Apple Universal Linking, can I use a http://
domain? If so, how do I do it? Right now if I load up the universal link, it just shows the dictionary inside the apple-app-site-association
file, which I'm pretty sure is not supposed to happen. I'm told it's supposed to send a NSUserActivity
object to my app delegate. How can I accomplish this with a http://
link?
It is not possible to trigger a custom URI scheme without showing an alert to the user. This used to be possible in iOS 8, but iOS 9 started showing the alert for all apps. And iOS 10.3 has extended that even to the App Store itself. You cannot bypass this. Universal Links were created to replace URI schemes for this behavior, so you do need to use them instead.
From your description, I believe you may be misunderstanding how Universal Links work. To answer the literal questions you asked first, no the Universal Link URL itself does not need to be on the https://
protocol, and yes, the apple-app-site-association
must be served over https://
without redirects.
However, it sounds like you're trying to serve the content of the apple-app-site-association
file for every Universal Link. That is not the correct implementation — the AASA file is hosted only at https://example.com/apple-app-site-association
, and iOS automatically retrieves it when the app is installed. After that, any URL on example.com
that matches the criteria in the AASA file will be eligible for Universal Links.
All of that said, you really don't want to built out this system on your own. I suggest looking into Firebase Dynamic Links or Branch.io (full disclosure: I'm on the Branch team).
1) Is it really impossible to work around the confirmation prompt using a custom URL scheme (myscheme://)? If it's not impossible, how can I do this?
That is possible.
1) set your app scheme like myapp
2) create the following html file and put it into the web
<html>
<head>
<link rel="apple-touch-icon" href="https://myapp.com/path/to/shortcut-icon.png" />
<meta name="apple-mobile-web-app-capable" content="yes" />
</head>
<script>
window.onload = function() {
if (("standalone" in window.navigator) && window.navigator.standalone) {
window.location.href = 'myapp://open'
}
}
</script>
</html>
3) open the html file with safari and "add to home screen"
4) open the home screen icon and your native app will launch
The point is the meta tag.
<meta name="apple-mobile-web-app-capable" content="yes" />
Without this, safari will launch and confirmation prompt will appear.