无法获取Firebase动态链接

xj3cbfub  于 2022-12-24  发布在  其他
关注(0)|答案(1)|浏览(128)

我正在按照Firebase的教程在我的应用程序中实现直接链接:Firebase Dynamic Links
我的应用委托中的代码似乎从未正常运行。当我运行项目时,我可以使用链接并打开应用。但没有一条print语句将运行,因此我无法判断它是否成功运行:

import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        return true
    }
    
    func handleincomingDynamicLink(_ dynamicLink: DynamicLink) {
        guard let url = dynamicLink.url else {
            print("Thats weird. My dynamic object link has no url")
            return
        }
        print("Your incoming link parameter is \(url.absoluteString)")
    }

    func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
      let handled = DynamicLinks.dynamicLinks()
        .handleUniversalLink(userActivity.webpageURL!) { dynamiclink, error in
            guard error == nil else {
                print("Found an error! \(error!.localizedDescription)")
                return
            }
            if let dynamicLink = dynamiclink {
                self.handleincomingDynamicLink(dynamicLink)
            }
        }

      return handled
    }
    
    @available(iOS 9.0, *)
    func application(_ app: UIApplication, open url: URL,
                     options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
      return application(app, open: url,
                         sourceApplication: options[UIApplication.OpenURLOptionsKey
                           .sourceApplication] as? String,
                         annotation: "")
    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?,
                     annotation: Any) -> Bool {
      if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
        
        return true
      }
      return false
    }
    
    
    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }

}

在我使用链接后,Xcode给我这个错误:
[连接] nw_read_request_report [C1]接收失败,错误为"软件导致连接中止"

nhhxz33t

nhhxz33t1#

在SceneDelegate类中使用以下委托方法:

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

相关问题