简体   繁体   English

冷启动 iOS 14 时未处理 iOS Firebase 动态链接

[英]iOS Firebase Dynamic link not handled on cold start iOS 14

When opening dynamic links on my device, my function in SceneDelegate that handles dynamic links runs fine while the app is running in the background but not when the app is completely shut off.在我的设备上打开动态链接时,我在 SceneDelegate 中处理动态链接的函数在应用程序在后台运行时运行良好,但在应用程序完全关闭时则无法正常运行。 When I do click the dynamic link while the app is off, the app opens but the dynamic link is not handled.当我在应用程序关闭时单击动态链接时,应用程序会打开但不会处理动态链接。 My scene delegate function looks like this:我的场景委托函数如下所示:

SceneDelegate Function场景委托函数

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    guard let _ = (scene as? UIWindowScene) else { return }

    
    if let incomingURL = userActivity.webpageURL {
        print("Incoming URL is \(incomingURL)")
        _ = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
            guard error == nil else{
                print("Found an error! \(error!.localizedDescription)")
                return
            }
            if let dynamicLink = dynamicLink {
                self.handleIncomingDynamicLink(dynamicLink)
            }
        }
    }
}

any help understanding this issue is greatly appreciated!非常感谢理解这个问题的任何帮助!

Since your target is iOS 14 , You can use latest APIs, So you can use .onOpenURL() modifier on any view.由于您的目标是 iOS 14 ,您可以使用最新的 API,因此您可以在任何视图上使用.onOpenURL()修饰符。

.onOpenURL { url in
        
        _ = DynamicLinks.dynamicLinks().handleUniversalLink(url) { (dynamicLink, error) in
            guard error == nil else{
                print("Found an error! \(error!.localizedDescription)")
                return
            }
            if let dynamicLink = dynamicLink {
                self.handleIncomingDynamicLink(dynamicLink)
            }
        }
    }

I was having the same issue, but I used the solution proposed from @Yodagama and it works totally fine.我遇到了同样的问题,但我使用了@Yodagama 提出的解决方案,它工作得很好。 In my case I am loading a firebase dynamic link.就我而言,我正在加载 Firebase 动态链接。 The only problem I am facing is that if the user doesn't have the app installed, the link first redirects you to apple store to download it and once you have it you have to open the link again in order to perform the function.我面临的唯一问题是,如果用户没有安装该应用程序,该链接首先会将您重定向到 Apple Store 进行下载,一旦您拥有它,您必须再次打开该链接才能执行该功能。

I am putting my code here, hope it helps somebody:我把我的代码放在这里,希望它可以帮助某人:

import SwiftUI
import Firebase

 @main
 struct Universal_Link_SwiftUI2_0App: App {

init() {
  FirebaseApp.configure()
}

var body: some Scene {
    
    WindowGroup {
        ContentView().onOpenURL { url in
            
            _ = DynamicLinks.dynamicLinks().handleUniversalLink(url) { (dynamicLink, error) in
                guard error == nil else{
                    print("Found an error! \(error!.localizedDescription)")
                    return
                }
                if let dynamicLink = dynamicLink {                         
                    self.handleIncomingDynamicLink(dynamicLink)
                }
            }
        }
     }
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM