iOS Swift 5 未调用 Deeplink userActivity 方法

iOS Swift 5 Deeplink userActivity Method not called

在 Swift 4 中,它在所有设备和 iOS 版本中工作正常。

升级到swift5 deeplink后打开app,但是没有调用userActivity方法

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let url = userActivity.webpageURL
        else { return false }
        print(url)
        return true
    }

我们的 App 支持 iOS10 及以上。

如果您通过 SceneDelegate 设置初始 viewController。您需要将其添加到 SceneDelegate

    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
              let url = userActivity.webpageURL else {
                  return
              }
        print(url)
    }

restorationHandler 回调类型已从 [Any] 更改为 [UIUserActivityRestoring] 然后它对我来说工作正常。

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let url = userActivity.webpageURL
        else { return false }
        print(url)
        return true
    }