Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to setup a redirect to app using Universal Links but nothing is happening

Tags:

ios

swift

So I have the following apple-app-site-association on my site, located at stage.domain.com/apple-app-site-association:

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "TEAMID.application.id.goes.here",
        "paths": ["*"]
      }
    ]
  }
}

I've set my Associated Domains as applinks:stage.domain.com

But when I try to navigate to stage.domain.com in Safari, it doesn't register and I stay in the browser. Is there anything else I need to do? I know that I need to eventually set routing up in the app for various pages, but that isn't a necessary requirement is it? It should just pull up the app without anything else? Or am I missing something?

Also, my restoration handler:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    print("DEBUG GETS TO NSURL?")

    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let url = userActivity.webpageURL

        else
    {return false}

    print("DEBUG GETS TO URL")

    return true
}

It gets to neither debug condition.

like image 971
Steven Matthews Avatar asked Apr 21 '18 01:04

Steven Matthews


People also ask

Do universal links work with redirects?

By definition, Universal Links do not work when they are redirected from another URL. This limit is meant as a security measure, preventing a website from opening apps without explicit user intention.

How do I test universal link?

TEST THE UNIVERSAL LINKS Run the application on the simulator once to make sure the application is installed and running fine. 2. Keep the same simulator launched and running. Go to your simulator browser and open type the ngrok domain address i.e., https://1bd39880fbad.ngrok.io in my case.


2 Answers

Did you already go through the debugging steps here: https://developer.apple.com/library/content/qa/qa1916/_index.html

I found the validation tool linked to in step one of the diagnostic section of the above reference to be quite helpful. It will verify that you set the app association file up correctly, and often give some guidance if you didn’t.

Update:

Based on your comment below regarding the link not working in Safari, I'd suggest verifying that your universal link setting for that domain didn't get disabled on your test device.

Specifically:

  • If a user opens a universal link and is taken to the app, there is a shortcut in the top right of the status bar which, if tapped, takes the user to the web version of the link and also disables the universal link opening the app. To re-enable the universal link for your app, you can paste the link into an app like Notes or Messages, long press on it, and choose "Open in... [Your App]".

  • The other possibility is that your web page in Safari is trying to open the universal link via Javascript or wrapped in a redirect. Neither of these will work.

There are more details in this blog post, along with some other universal link issues: https://medium.com/mobile-growth/the-things-i-hate-and-you-should-know-about-apple-universal-links-5beb15f88a29

Additional Update:

I have a suspicion regarding your scenario: Apple does not trigger a universal link when the user directly types a URL to a universal link domain into the Safari address bar. The assumption being that if the user explicitly entered a URL into the Safari address bar, the correct response is to open the URL in Safari. In this scenario, Safari inserts the banner that allows the user to intentionally open the link in the app to the top of the page.

You can test this yourself:

  1. Install the Twitter app
  2. Paste the URL to a tweet in Safari's address bar. Note that it opens the tweet page in the browser. Tap the banner with the "Open" link at the top of the page to open it in the Twitter app.
  3. Open Safari again. Now Google the word "tweet" or otherwise find a page that has a link to a tweet (rather than typing or pasting the URL in the Safari address bar)
  4. Note that tapping the link opens the Twitter app instead of the page in Safari.
like image 104
Daniel Hall Avatar answered Oct 13 '22 00:10

Daniel Hall


If, when you access your site, it shows the universal links banner on top of the page, like this: https://i.stack.imgur.com/ZSQGK.jpg, you are doing it right.

If you click on Open, it should open the app. Then, if you try to click on a link to your website AFTER you opened your app through the banner, iOS should save your preferences and open the app directly, instead of going to Safari with the banner on top.

The way Universal Linking works, it does not allow the app to be opened by links without any consent of the user. Thus, the user must give permission at least one time before the app opens automatically.

like image 20
Kévin Avatar answered Oct 12 '22 23:10

Kévin