MadMac
MadMac

Reputation: 4993

Open universal link in app programmatically from browser

Is is possible to open a mobile app on iOS via a universal link programmatically or is this only possible via a user click?

I'm guessing this may not be allowed for security reasons.

Process:

  1. The user has the app "myapp" installed. I have a button/url in an email that the user receives.
  2. The user clicks the button/url which takes them to a webpage https://action.mypage.app. (The webpage url is actually wrapped in a sendgrid url).
  3. At https://action.mypage.app an Angular application logs the action the user has taken and then opens another url which is a universal link that will open in "myapp" e.g. https://open.myapp.app

Outcome: There are several outcomes on my test devices.

  1. Rather than the mobile app being opened the equivalent web page https://open.myapp.app is opened in the mobile browser. This has the banner at the top "Open in the myapp app" with the apps icon.

  2. Same as one but do not get the banner at all.

  3. Note that for some iOS devices I use rather than opening in the browser it pops up a message "Open this page in "myapp"?" Cancel Open. If I click open it opens in the app if I click cancel it opens in the browser as above.

Desired outcome:

The mobile app is opened rather than the web page.

Using a "user click":

It works fine if I have a webpage that has a button that opens the url https://open.myapp.app. This will open the mobile app no problems when the user clicks the button.

Other: I did note this article however the sub domain is not the same. The webpage is at https://action.mypage.app and the universal url is https://open.myapp.app:

When a user browses your website in Safari and taps a universal link in the same domain, the system opens that link in Safari, respecting the user’s most likely intent to continue within the browser. If the user taps a universal link in a different domain, the system opens the link in your app.

Update:

I currently have this working by having a direct link from the email button/url to https://open.myapp.app and this opens in the app as expected. I have removed the Sendgrid tracking and any custom action logging I am doing. I guess if I want to log the action I will need to do that from the mobile app when it opens.

Upvotes: 4

Views: 3520

Answers (1)

J3fFury
J3fFury

Reputation: 41

Apple has limited Universal Links in certain situations:

  • Universal Links will not work if you paste the link into the browser URL field.
  • Universal Links will not work with a user-driven element click on the same domain. For example, if there is a Universal Link on google.com pointing to a different Universal Link on google.com, it will not open the app.
  • Universal Links cannot be triggered via Javascript (in window.onload or via a .click() call on an element) unless it is part of a user action.

https://help.branch.io/developers-hub/docs/ios-universal-links#appsbrowsers-that-support-universal-links

What I suppose to do is to add an extra domain to host the buttons, and use window.location.href instead of a href

Upvotes: 4

Related Questions