title: Firebase Dynamic Link leads to "Dynamic Link not found" when app not installed
body: <p>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”. </p>
  
  <p>Here is the debug link: <a href="https://www.nomadflare.com/app/?ibi=com%2Enomadflare%2ENomadFlare&amp;imv=1%2E0&amp;ofl=https%3A%2F%2Fwww%2Enomadflare%2Ecom&amp;link=https%3A%2F%2Fnomadflare%2Ecom%2Fapp%2F%3Finvitedby%3DdZ3I3pK0KzcOGhO8AoVbBnn8XsO2&amp;d=1" rel="noreferrer">https://www.nomadflare.com/app/?ibi=com%2Enomadflare%2ENomadFlare&amp;imv=1%2E0&amp;ofl=https%3A%2F%2Fwww%2Enomadflare%2Ecom&amp;link=https%3A%2F%2Fnomadflare%2Ecom%2Fapp%2F%3Finvitedby%3DdZ3I3pK0KzcOGhO8AoVbBnn8XsO2&amp;d=1</a></p>
  
  <p>And here is how I configured the whole thing.
  In my Firebase project settings, I set the App Store ID and the Team ID:</p>
  
  <p><a href="https://i.stack.imgur.com/9NsY3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9NsY3.png" alt="Project settings in Firebase console"></a></p>
  
  <p>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):</p>
  
  <p><a href="https://i.stack.imgur.com/jtyG2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jtyG2.png" alt="Dynamic Links settings"></a></p>
  
  <p>With that I have the following on <a href="https://nomadflare.com/apple-app-site-association" rel="noreferrer">https://nomadflare.com/apple-app-site-association</a>:</p>
  
  <pre><code>{"applinks":{"apps":[],"details":[{"appID":"HLAKBN9F84.com.nomadflare.NomadFlare","paths":["NOT /_/*","/*"]}]}}
  </code></pre>
  
  <p>Then in my XCode project, I enabled Associated Domains in Capabilities, and set a first associated domain to <code>applinks:$(DYNAMIC_LINKS_DOMAIN)</code>, where DYNAMIC_LINKS_DOMAIN is a user-defined build setting that depends on the build configuration, but for prod is equal to <code>nomadflare.com</code>.</p>
  
  <p>In Info/URL Types, the custom URL scheme is <code>$(PRODUCT_BUNDLE_IDENTIFIER)</code> (again, depends on the build configuration, but for prod it's <code>com.nomadflare.NomadFlare</code>.</p>
  
  <p>And finally in my Swift code, I have the following function that is triggered when the user taps a Share button:</p>
  
  <pre class="lang-swift prettyprint-override"><code>    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)
          }
      }
  </code></pre>
  
  <p>And here are the relevant keys in my Info.plist:</p>
  
  <pre><code>&lt;key&gt;FirebaseDynamicLinksCustomDomains&lt;/key&gt;
  &lt;array&gt;
      &lt;string&gt;https://$(DYNAMIC_LINKS_DOMAIN)/app&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;LSApplicationQueriesSchemes&lt;/key&gt;
  &lt;key&gt;WebsiteUrl&lt;/key&gt;
  &lt;string&gt;$(WEBSITE_URL)&lt;/string&gt;
  &lt;key&gt;AppStoreID&lt;/key&gt;
  &lt;string&gt;1474350816&lt;/string&gt;
  </code></pre>
  
  <p>And <code>WEBSITE_URL</code> is yet another build-config-specific user-defined setting, whose value is <code>https://www.nomadflare.com</code> in production.</p>
  
  <p>I'm really not sure about what I put in the <code>link</code> part of my referral link though.</p>