12

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?

Mark Carols
  • 403
  • 4
  • 20
  • 1
    Were you able to achieve this ? If yes, please post it here. Thanks in advance. – Tejas K Jun 16 '17 at 05:34
  • @mark-carols, I'm also having the same use case: customer has an iOS app, he's redirected to browser for payment, and then after payment is done I need to redirect customer automatically from browser to the app to finish the payment without any confirmation. If customer sees a confirmation and cancels the redirect from browser to the app, then I can not correctly complete the payment. So was you able to find the solution? – AbstractVoid Nov 10 '17 at 11:27

2 Answers2

9

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).

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • 1
    Ok, I guess I should've pointed out my use case a little better. My situation really isn't all that complicated: I have a button in my app which opens a URL in Safari to complete a payment on a web page. After the user is done, a pre-determined URL is supposed to open and this URL (either the scheme or a universal link?) has to re-open the app and continue from where the user left off to the web page. I don't want the user to see a confirmation prompt after the payment is done. This transition from web page back to the app should happen automatically. – Mark Carols Apr 20 '17 at 06:37
  • 1
    Basically, all I need is a valid URL which I can pass in as the return URL that gets opened after the payment process is done. This URL should open the app without asking for confirmation. It seems very unlikely this process is so complex that I would have to use Firebase or Branch for this, since this is literally just one URL taking me from one pre-determined starting point to one pre-determined destination. – Mark Carols Apr 20 '17 at 06:41
  • I suspect you need to use a built in webview for this. I've never closely paid attention, but I believe that is how I have typically seen this implemented in other apps. – Alex Bauer Apr 21 '17 at 07:16
  • 1
    I can't use built-in webviews, since they don't allow the user to open apps, which might be necessary for completing payments (i.e. banking apps such as PayPal). – Mark Carols Apr 21 '17 at 07:28
  • That is not actually true. Web views can open apps, just like Safari. However, there is a reason why this alert exists, and why things like Apple Pay and the PayPal SDK exist. Perhaps you should investigate the typical ways to handle this rather than trying to hack your own? – Alex Bauer Apr 21 '17 at 14:18
  • 2
    The whole reason I'm trying to get this work to work is because of a payment SDK I'm implementing, and the SDK is explicitly telling me NOT to process payments in a web view, because it won't work. Even if that SDK wouldn't have told me that, I would still know that it wouldn't work, because I have plenty of experience making payments on my iPhone and every payment app I've ever used ALWAYS opens up Safari to authenticate payments. There would be a reason for that too. – Mark Carols Apr 21 '17 at 16:25
  • 1
    I appreciate the help, but I really don't need any suggestions on how to process my payments, I'm literally just asking how to automatically open my app without the alert, and I know for a fact that this is possible as well, because there's a boatload of apps out there that can open up without any confirmation whatsoever (i.e. YouTube, Twitter, Facebook, etc.). If it's possible for them, it should be possible for me too. – Mark Carols Apr 21 '17 at 16:29
  • 1
    @MarkCarols to my knowledge this is not possible without Universal Links. If you find a way, please post your own answer with what you discover. – Alex Bauer Apr 21 '17 at 20:45
  • I will. I tried out Branch, by the way, but I couldn't get the link to work. I configured my app in Link Settings, but when I type in the URL in my Safari browser, it goes directly to the redirect URL, even though I have my app installed and running in the background. Am I supposed to do anything else, other than configuring my app in the Link Settings? – Mark Carols Apr 21 '17 at 20:48
  • Assuming you got everything set up, Universal Links don't work when entered directly into the Safari URL bar (regardless of whether they are Branch or not). More troubleshooting info on that [here](https://dev.branch.io/getting-started/universal-app-links/support/ios/#troubleshooting-universal-links) – Alex Bauer Apr 21 '17 at 20:50
  • I followed the instructions: I pasted the link in my Notes app and then tapped it from there, but it still opened Safari and went to my redirect URL. Am I supposed to do anything else, other than setting up the app in Link Settings and creating a quick link? – Mark Carols Apr 21 '17 at 21:02
  • Yes, there is a [SDK integration process](https://dev.branch.io/getting-started/) you'll need to complete. Feel free to reach out to the Branch [Integrations Team](https://support.branch.io/support/tickets/new) if you have specific questions! (StackOverflow is probably going to cut this comment thread off pretty soon, so I won't be able to respond further here) – Alex Bauer Apr 21 '17 at 21:05
0
  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 with some hacky tricks and BAD user experience. It requires user to press "add to home screen" button, so I don't recommend this solution in most cases.

  1. set your app scheme like myapp

  2. create the following html file and put it into the web

    window.onload = function() { if (("standalone" in window.navigator) && window.navigator.standalone) { window.location.href = 'myapp://open' } }
  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.

Kazuya Gosho
  • 996
  • 13
  • 14
  • 1
    This doesn't seem like a very convenient solution, if the user first has to add the web page to the home screen for this to work. – rodskagg Oct 08 '18 at 13:09
  • 1
    Yeah exactly. I found the possibility when I searched the "add to home screen" feature so shared this. Sorry if this answer is not suit for the question. – Kazuya Gosho Oct 09 '18 at 15:27