开发者社区> 问答> 正文

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!)
   }
}

APP委托

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

展开
收起
游客5akardh5cojhg 2019-12-07 19:19:36 1029 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载