1

在 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)

但是,这对我不起作用。我仍然看到警告并且链接仍未处理。

你能帮我解决这个问题吗?或者你有更好的解决方案:]

4

2 回答 2

0

抱歉,关于这个问题的答案迟了。

我们联系了 Localytics 和 Firebase。Localytics 为我们提供了一个需要从自动集成切换到手动集成的解决方案。虽然使用手动集成有点烦人,但它解决了问题:]

于 2017-03-13T16:23:40.310 回答
0

花了将近一整天的时间后,我发现了问题所在。

下面的解决方案就像魅力一样!

您可以通过FirebaseAppDelegateProxyEnabledNO应用程序的info.plist

https://docs.localytics.com/dev/ios.html#integrating-with-firebase

干杯

于 2018-09-12T12:45:18.053 回答