I have a problem with DynamicLinks. If the app is installed, on an iPhone, the dynamic link opens the iOS app with the deep link and everything works fine. But if the app is not installed, instead of showing the app’s page in the Apple App Store, it shows a web page that says “Dynamic link not found”.
Here is the debug link: https://www.nomadflare.com/app/?ibi=com%2Enomadflare%2ENomadFlare&imv=1%2E0&ofl=https%3A%2F%2Fwww%2Enomadflare%2Ecom&link=https%3A%2F%2Fnomadflare%2Ecom%2Fapp%2F%3Finvitedby%3DdZ3I3pK0KzcOGhO8AoVbBnn8XsO2&d=1
And here is how I configured the whole thing. In my Firebase project settings, I set the App Store ID and the Team ID:
In my Dynamic Links settings, I defined a new URL prefix with my custom domain and a subpath (I have a website at the root of my domain, hosted on Firebase Hosting):
With that I have the following on https://nomadflare.com/apple-app-site-association:
{"applinks":{"apps":[],"details":[{"appID":"HLAKBN9F84.com.nomadflare.NomadFlare","paths":["NOT /_/*","/*"]}]}}
Then in my XCode project, I enabled Associated Domains in Capabilities, and set a first associated domain to applinks:$(DYNAMIC_LINKS_DOMAIN)
, where DYNAMIC_LINKS_DOMAIN is a user-defined build setting that depends on the build configuration, but for prod is equal to nomadflare.com
.
In Info/URL Types, the custom URL scheme is $(PRODUCT_BUNDLE_IDENTIFIER)
(again, depends on the build configuration, but for prod it's com.nomadflare.NomadFlare
.
And finally in my Swift code, I have the following function that is triggered when the user taps a Share button:
func share() {
guard let uid = Session.shared.authenticatedUser?.id else {
return
}
guard let customDomains = Bundle.main.object(forInfoDictionaryKey: "FirebaseDynamicLinksCustomDomains") as? [String],
let bundleIdentifier = Bundle.main.bundleIdentifier,
let websiteUrlString = Bundle.main.object(forInfoDictionaryKey: "WebsiteUrl") as? String,
let websiteUrl = URL(string: websiteUrlString),
let appStoreID = Bundle.main.object(forInfoDictionaryKey: "AppStoreID") as? String else {
return
}
let urlBase = customDomains[0]
let link = URL(string: "\(urlBase)/?invitedby=\(uid)")
let referralLink = DynamicLinkComponents(link: link!, domainURIPrefix: urlBase)
referralLink?.iOSParameters = DynamicLinkIOSParameters(bundleID: bundleIdentifier)
referralLink?.iOSParameters?.minimumAppVersion = "1.0.0"
referralLink?.iOSParameters?.appStoreID = appStoreID
referralLink?.otherPlatformParameters = DynamicLinkOtherPlatformParameters()
referralLink?.otherPlatformParameters?.fallbackUrl = websiteUrl
KRProgressHUD.show()
referralLink?.shorten { (shortURL, warnings, error) in
KRProgressHUD.dismiss()
if let error = error {
print(error.localizedDescription)
return
}
let invitationUrl = shortURL
let text = NSLocalizedString("Check out NomadFlare. It's a dating app for travellers and digital nomads.", comment: "")
let shareAll = [text, invitationUrl!] as [Any]
let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
}
}
And here are the relevant keys in my Info.plist:
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://$(DYNAMIC_LINKS_DOMAIN)/app</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<key>WebsiteUrl</key>
<string>$(WEBSITE_URL)</string>
<key>AppStoreID</key>
<string>1474350816</string>
And WEBSITE_URL
is yet another build-config-specific user-defined setting, whose value is https://www.nomadflare.com
in production.
I'm really not sure about what I put in the link
part of my referral link though.