实施 Localytics 时,Firebase Dynamic Link 找不到 continueUserActivity

Firebase Dynamic Link can't find continueUserActivity when Localytics implemented

在 iOS 上实施 Firebase Dynamic link 时,单击打开动态 link 时调试控制台中出现错误消息:

FIRAnalytics/WARNING Implementation of application:continueUserActivity:restorationHandler: not found. Please add the handler into your App Delegate. Class: 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 试图在 Localytics 的 LLAppDelegateProxy 中调用 application:continueUserActivity:restorationHandler: 而不是 AppDelegate.swift。还有一个 GitHub 问题 post 来自 Branch.io:https://github.com/BranchMetrics/ios-branch-deep-linking/issues/485

post 声明 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)

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

你能帮我解决方法 swizzling 或者你有更好的解决方案:]

抱歉,关于这个问题的回答太晚了。

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

折腾了将近一整天,问题终于解决了。

下面的解决方案非常有效!

您可以通过将 FirebaseAppDelegateProxyEnabled 设置为 NO 来防止 Firebase 混淆 AppDelegate 中的方法在您应用的 info.plist

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

干杯