Search code examples
iosswiftfirebase-dynamic-links

Firebase Dynamic link handling always gives error


Thank you in advanced for giving your valuable time for reading this.

I have tried to implement dynamic link through firebase sdk.
Have gone through provided documents for implementing this by firebase.

Issue I face is when I share dynamic link through application generated using below code

    guard let link = URL(string: "\(Constant.dynamicLinkBaseUrl)\(urlPathComponent)/\(encShareDetail ?? "")") else { return }
    let dynamicLinksDomainURIPrefix = Constant.DomainURIPrefix
    let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)
    linkBuilder?.iOSParameters = DynamicLinkIOSParameters(bundleID: Bundle.main.bundleIdentifier ?? Constant.AppBundleID)
    
    linkBuilder?.navigationInfoParameters?.isForcedRedirectEnabled = true
    linkBuilder?.iOSParameters?.fallbackURL = URL(string:Constant.AppStoreFallbackUrl)
    linkBuilder?.androidParameters = DynamicLinkAndroidParameters(packageName: Constant.AndroidPackageName)
    linkBuilder?.androidParameters?.fallbackURL = URL(string: Constant.AndroidFallbackUrl)
    linkBuilder?.shorten() { url, warnings, error in
      print("URL :: \(String(describing: url?.absoluteString))\nWarnings :: \(String(describing: warnings?.debugDescription))\nError :: \(String(describing: error?.localizedDescription))")
      guard let url = url, error == nil else { return }
      print("The short URL is: \(url)")
      tabBarControllerObj?.presentDefaultShare(videoURL: url.absoluteString)
    }

On taping the generated link in device, my application is launched and it am able to get the generated dynamic link in

scene(_ scene: UIScene, continue userActivity: NSUserActivity)

method, I'm able to get the link with the below code

guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
          let url = userActivity.webpageURL,
          let host = url.host else {
      return
    }
    print("URL :: \(url.absoluteString)\nHost :: \(host.debugDescription)")

but not able to get the deep link I have created as when I called the method

DynamicLinks.dynamicLinks().handleUniversalLink(url)

It returns with error as "The operation couldn’t be completed. Universal link URL could not be parsed by Dynamic Links."

Don't found any solution related to this as the same Dynamic link is working fine for Android app.

Please help me as I'm stuck with it for around 4 days.Flow Diagram for dynamic link seems fine too.


Solution

  • I was able to solve this issue by adding all my url prefixes to info.plist.

    <key>FirebaseDynamicLinksCustomDomains</key>
            <array>
              <string>https://<custom domain>/login</string>
              <string>https://<custom domain>/</string>
            </array>
    

    More details at https://firebase.google.com/docs/dynamic-links/custom-domains#console