iosfirebasefirebase-dynamic-linksios-universal-linksuiscenedelegate

Firebase Dynamic Link Not working on App installation Scenedelegte


I'm using Firebase DynamicLinks SDK to show the Invite Popup to users, which is working fine when the app is installed for both Cases

The link is redirecting the User to the store when the app is not installed. But it is not showing the Invite Popup, seems when the user installs the app and taps the open button from the app store, it does not carry the link info with it.

Below is the code in my scenedelegate

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let windowScene = (scene as? UIWindowScene) else { return }
    let initialWindow = UIWindow(windowScene: windowScene)
    initialWindow.makeKeyAndVisible()
    AppSharedPoint.shared.setupWindow(window ?? initialWindow) {
        if let url = connectionOptions.userActivities.first?.webpageURL {
            AppSharedPoint.shared.handle(link: url)
        } else if let url = connectionOptions.urlContexts.first?.url {
            AppSharedPoint.shared.handle(link: url)
        } else if let url = connectionOptions.userActivities.first?.referrerURL {
            AppSharedPoint.shared.handle(link: url)
        }
    }
}

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    if let url = userActivity.webpageURL {
        AppSharedPoint.shared.handle(link: url)
    } else if let url = userActivity.referrerURL {
        AppSharedPoint.shared.handle(link: url)
    }
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let firstUrl = URLContexts.first?.url else {
        return
    }
    AppSharedPoint.shared.handle(link: firstUrl)
}

Please suggest a way to fix or any way to debug this when app is getting installed from Appstore via link.

Thanks


Solution

  • Please try to write the below method in appdelegate. You will get a dynamic link.

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
            if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
                print(dynamicLink.url)
                return true
            } else {
                return false
            }
        }