It seems that since iOS 9 if a user has already been redirected to an app from a website, then future links to that website automatically open the app.
How can I detect inside the iOS app what the link was that the user clicked so that I can serve the correct content?
In my case, a user has already installed the app, does a forgot password, and clicks the link in the email. On a desktop it works fine, but on iOS it just takes them to the app and my app does not know the context.
It is a Swift app that is mostly a webview serving the mobile version of our web app.
UPDATE:
Here are some details about the situation:
- The iOS app has a URL Scheme defined (ourUniqueOrganizationName)
- When a user logs in, I use js to check if they are on iOS and if so, redirect them to a page that provides a link to download the app (which is served by our own web server, not via the app store, via a link like
itms-services://?action=download-manifest&url=https://www.etcetcetc.org/apps/name-of-the-app/manifest.plist
- Once they click the download button, iOS asks the user if they want to download the app, and if they say yes, it does so in the background and they are left sitting on the same webpage.
- On that page, I display instructions on how to "Trust" our organization in the settings of their phone (it is an Enterprise app, so this annoying step is required)
- The last thing on the page is a link to "Open the App", which points to
ourUniqueOrganizationName://go
Not sure if this is relevant, but I actually have a second URL scheme defined, app
, which is used to by the js of the website (when the site is loaded in a webview) to send data to the app like:
window.location = "app://do/some/thing"
which the app can catch via func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {}
To be clear, inside that shouldStartLoadWith
I am only testing that request.url?.scheme
equals "app"
. This function does not get involved with the other URL scheme, ourUniqueOrganizationName
, as I understand that just having that defined in the info.plist is enough for websites to open the app using that as the scheme.
UPDATE # 2:
I finally realized that I did, in fact, have Universal Links on so the behavior I was seeing should have been expected!