ios – 当app不在后台时打开通用链接

ios – 当app不在后台时打开通用链接,第1张

概述我有类似的问题 iOS: apple universal link if app is not open?.当我点击通用链接时,应用程序无法进入func应用程序(_应用程序:UIApplication,继续userActivity:NSUserActivity,restorationHandler:@escaping([Any]?) – > Void) – > Bool {}如果它不在后台. 我在 我有类似的问题 iOS: apple universal link if app is not open?.当我点击通用链接时,应用程序无法进入func应用程序(_应用程序:UIApplication,继续userActivity:NSUserActivity,restorationHandler:@escaPing([Any]?) – > VoID) – > Bool {}如果它不在后台.

我在dIDFinishLaunchingWithOptions中添加了一些代码.但它不起作用.非常感谢你如果有人可以提供帮助.

@H_502_13@func application(_ application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let activityDic = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] if activityDic != nil { // Continue activity here self.window?.rootVIEwController?.restoreUserActivityState(activityDic as! NSUserActivity) } return true}func application(_ application: UIApplication,continue userActivity: NSUserActivity,restorationHandler: @escaPing ([Any]?) -> VoID) -> Bool { if userActivity.activityType == NSUserActivityTypebrowsingWeb { if let controller = UIStoryboard(name: "Main",bundle: nil).instantiateVIEwController(withIDentifIEr: "xxx") as? XXXtableVIEwController { if let window = self.window,let rootVIEwController = window.rootVIEwController { var currentController = rootVIEwController while let presentedController = currentController.presentedVIEwController { currentController = presentedController } currentController.present(controller,animated: true,completion: nil) } } } return true}解决方法 将此代码放入dIDFinishLaunchingWithOptions函数以在应用程序启动时打开URL(Swift 3代码):

@H_502_13@if let url = launchOptions?[UIApplicationLaunchOptionsKey.url] as? URL { //Deeplink // process url here } else if let activityDictionary = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] as? [AnyHashable: Any] { //Universal link for key in activityDictionary.keys { if let userActivity = activityDictionary[key] as? NSUserActivity { if let url = userActivity.webpageURL { // process url here } } } } 总结

以上是内存溢出为你收集整理的ios – 当app不在后台时打开通用链接全部内容,希望文章能够帮你解决ios – 当app不在后台时打开通用链接所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1059975.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存