IOS 13 无法处理通用链接单击,当应用程序通过链接单击打开时



我正在尝试处理通用链接单击打开的应用程序。 在iOS 13下方,它运行良好,但对于iOS 13,它只能在后台运行的应用程序。如果应用程序无法在前台或后台工作,单击链接将打开未调用的应用程序继续用户活动功能。我还试图让它在现场委托人来委托。但仍然没有打电话 我的代码在下面有什么问题?

场景委托

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
if connectionOptions.userActivities.first != nil {
self.scene(scene, continue: userActivity!)
}
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
continueUserActivity(userActivity: userActivity)
}
func continueUserActivity(userActivity : NSUserActivity){
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
let dataDict:[String: String] = [AppLinkManager.appLinkExtraKey: url.absoluteString]
NotificationCenter.default.post(name: .didReceiveAppLink, object: nil, userInfo: dataDict)
}
}

应用委托

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if let userActivityDict = launchOptions?[.userActivityDictionary] as? [AnyHashable : Any],
let userActivity = userActivityDict["UIApplicationLaunchOptionsUserActivityKey"] as? NSUserActivity {
continueUserActivity(userActivity: userActivity)
}
return true
} 
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool  {
continueUserActivity(userActivity: userActivity)
return true
}

func continueUserActivity(userActivity : NSUserActivity){
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
let dataDict:[String: String] = [AppLinkManager.appLinkExtraKey: url.absoluteString]
NotificationCenter.default.post(name: .didReceiveAppLink, object: nil, userInfo: dataDict)
}  
}

您是否尝试过在SceneDelegate中实现continue userActivity函数:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { }

我在使用Firebase DynamicLink时遇到了同样的问题,看起来UniversalLinks(可能还有其他几个API(在SceneDelegate上使用此回调。

因此,如果您的目标是iOS 13及更低版本,请尝试同时实现SceneDelegateAppDelegate

相关内容

  • 没有找到相关文章

最新更新