在 iOS 上实现 Firebase 动态链接时,当您点击打开动态链接时,调试控制台中会出现错误消息:
FIRAnalytics/WARNING 应用程序的实现:continueUserActivity:restorationHandler:未找到。请将处理程序添加到您的 App Delegate 中。类:LLAppDelegateProxy
我创建了一个最小化项目来重现此问题。新项目只包含
Pod 'Localytics'
Pod 'Firebase/DynamicLinks’
并且唯一的添加代码AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
Localytics.autoIntegrate("apikey", launchOptions: launchOptions)
return true
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let dynamicLink = FIRDynamicLinks.dynamicLinks()?.dynamicLink(fromCustomSchemeURL: url)
if let dynamicLink = dynamicLink {
print(dynamicLink.url)
return true
}
return false
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard let dynamicLinks = FIRDynamicLinks.dynamicLinks() else {
return false
}
let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
print(dynamiclink?.url)
}
return handled
}
看起来 Firebase 尝试调用application:continueUserActivity:restorationHandler:
Localytics'LLAppDelegateProxy
而不是AppDelegate.swift
. Branch.io 也有一个 GitHub 问题帖子:https ://github.com/BranchMetrics/ios-branch-deep-linking/issues/485
该帖子指出,Google Analytics 和 Localytics 之间存在冲突,导致 Branch 无法application:continueUserActivity:restorationHandler:
在正确的位置找到该功能。
我按照他们的第三个建议来改变方法 swizzling:
//Their solution in Objc
SwizzleInstanceSelectorWithNewSelector(
[[UIApplication sharedApplication].delegate class],
@selector(application:continueUserActivity:restorationHandler:),
[self class],
@selector(BRapplication:continueUserActivity:restorationHandler:)
);
//My swift version in AppDelegate.swift
let originalSelector = #selector(AppDelegate.application(_:continueUserActivity:restorationHandler:))
let swizzledSelector = #selector(AppDelegate.firApplication(_:continueUserActivity:restorationHandler:))
let originalMethod = class_getClassMethod(AppDelegate.self, originalSelector)
let swizzledMethod = class_getClassMethod(AppDelegate.self, swizzledSelector)
method_exchangeImplementations(originalMethod, swizzledMethod)
但是,这对我不起作用。我仍然看到警告并且链接仍未处理。
你能帮我解决这个问题吗?或者你有更好的解决方案:]