Firebase动态链接在应用安装时不起作用Scenedelegte

huangapple go评论71阅读模式
英文:

Firebase Dynamic Link Not working on App installation Scenedelegte

问题

我正在使用Firebase DynamicLinks SDK来向用户显示邀请弹窗,在以下两种情况下运行正常:

  • 当应用处于后台
  • 当应用被杀死

当应用未安装时,链接将重定向用户到应用商店。但在这种情况下,它不显示邀请弹窗,似乎当用户从应用商店安装应用并点击打开按钮时,不会携带链接信息。

以下是我的scenedelegate中的代码:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    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)
}

请建议一种修复方法或在应用从App Store通过链接安装时进行调试的方法。

谢谢!

英文:

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

  • When App Is in the background
  • When the App is Killed

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

答案1

得分: 1

请尝试将以下方法写入AppDelegate中。您将获得一个动态链接。

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
    }
}
英文:

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
        }
    }

huangapple
  • 本文由 发表于 2023年5月28日 17:11:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76350739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定