I have a scenario where I need to have a custom solution to open app using Apple’s provided universal links. I have already set up a custom domain and hosted apple-app-site-association
file on the root of my custom domain. This AASA file is properly hosted as I have validated it by using [https://branch.io/resources/aasa-validator/%5C](this) link.
After all the development required to do for app id, i.e. enabling associated domain capability and adding it in the Xcode required place my custom domain link successfully open the app if installed and I can easily get the path for any kind of further navigation in the app. I also have added a support on my domain to open app store if the app is not found in the phone. Everything works as expected.
The real problem is when I don’t have app in my phone and my universal link helps me install the app, I want to have my universal link in first launch after installation so that I could do required actions in the app or do necessary navigations if required. This will help me identify which link/campaign/ad has encouraged user to install the app.
There are multiple third parties which help do so and successfully provides the link like Firebase, AppsFlyer, Adjust or Branch. But I want to implement my own solution for that.
Please help me in this regard and suggest how I can achieve it.
Lots of Thanks in advance!
I tried adding a param in my app store link hoping that I would get that link on first launch after installation in AppDelegate’s func application(_, open: URL, options [UIApplication.OpenURLOptionsKey: Any])
method as follows
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
// Here I am expecting that url could be like
'https://apps.apple.com/app/idYOUR_APP_ID?token={randomly_generated_string}'
}
As I understood from already provided solutions for deferred deep linking that we can have the AppStore link instead of actual universal link in this AppDelegate method and on backend before opening store we would save our universal link against that token
above. And on launch of the app that token can be used to fetch actual universal link saved on our backend. But this didn’t happen as I get the following in url
param in the above method on first launch after the installation of the app,
{bundle_identifier}://google/link/?request_ip_version=IP_V4&match_message=No pre-install link matched for this device.
And that’s how I am testing this scenario:
-
I uninstall the app from my device
-
Click my universal link which directs me to my custom domain hosted page in case the app is not found in the phone.
-
That page redirects user to App Store to let them install the app first
-
Then I manually run the app from Xcode on debugger as this implementation is not yet published on the store.
-
This way it successfully invokes the AppDelegate’s
func application(_, open: URL, options [UIApplication.OpenURLOptionsKey: Any])
method on first launch.
Plus, following is my JavaScript code in index.html
which I have hosted on my custom domain in order to in order to be used if the app is not installed on the device.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Open Store</title>
</head>
<body>
<div style="margin: 0 auto; width: 10rem">
<p style="padding-top: 100px">
<a href="https://apps.apple.com/us/app/idYOUR_APP_ID?token=1234">
Open in App Store</a>
</p>
</div>
<script>
// Fallback to the App Store if the app is not installed
window.addEventListener('load', function() {
setTimeout(function() {
// Redirect to the App Store after a delay
window.location.href = "https://apps.apple.com/us/app/idYOUR_APP_ID?token=1234";
}, 2000);
});
</script>
</body>
</html>
Here if you see I have hardcoded token=1234
in the App Store url in order to check that either I get this in app delegate on first launch. But no luck.
Faraz Raza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.