gpt4 book ai didi

ios - Firebase Deeplink 不触发应用程序 :continueUserActivity:restorationHandler, Swift 4.2 Xcode10。

转载 作者:行者123 更新时间:2023-11-28 10:37:10 24 4
gpt4 key购买 nike

我遵循了 Firebase Dynamic Links 中的所有步骤文档。

关联的域处于事件状态并且域已经添加,我还在信息选项卡中添加了 URL 方案,并以编程方式在 launchOptions 函数中添加。

深层链接正在打开应用程序,但在单击动态链接后触发的唯一方法是 willContinueUserActivityWithType,它返回 nil userActivity

在文档中提到,如果应用程序在后台运行,则 continueUserActivity 必须触发,但在我的情况下没有发生,我可以找到任何其他方式来获取深度链接数据。

这是我的 AppDelegate 代码:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let options = FirebaseOptions(contentsOfFile: filePath)
options?.deepLinkURLScheme = "com.example"
FirebaseApp.configure(options: options!)
.
.
.

}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
print("applicationDidBecomeActive")
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {

if let incomigURL = userActivity?.webpageURL{
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomigURL) { (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url {
self.handleIncomingDynamicLink(dynamicLink: dynamiclink)
} else {
print("willContinueUserActivityWithType | dynamiclink = nil")
}
}
return linkHandle
}
print("willContinueUserActivityWithType | userActivity = nil")
return false
}

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
if let incomigURL = userActivity.webpageURL{
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomigURL) { (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url {
self.handleIncomingDynamicLink(dynamicLink: dynamiclink)
} else {
print("continueUserActivity | dynamiclink = nil")
}
}
return linkHandle
}
print("continueUserActivity = nil")
return false
}

@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 {
print("Handle deep link.")
return true
}

func handleIncomingDynamicLink(dynamicLink: DynamicLink){
print("Your dynamic link parameter is = \(String(describing: dynamicLink.url))")
}

}

最佳答案

在 swift 4.2 中将即时方法更改为:

  func application(_ application: UIApplication, 
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool

所以为了处理 Firebase 深层链接 NSUserActivity 函数必须像这样:

func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomigURL = userActivity.webpageURL{
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomigURL) { (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url {
self.handleIncomingDynamicLink(dynamicLink: dynamiclink)
} else {
print("dynamiclink = nil")
}
}
return linkHandle
}
print("userActivity = nil")
return false
}

特别感谢user1376400

关于ios - Firebase Deeplink 不触发应用程序 :continueUserActivity:restorationHandler, Swift 4.2 Xcode10。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52876629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com