我正在尝试通过通用链接点击来处理打开的应用。低于ios 13可以正常工作,但对于ios 13来说,它只能在后台运行的应用程序。如果应用程序不能在前台或后台运行,则单击链接可打开不称为 continue userActivity 功能的应用程序。我也尝试在场景委托willconnnect中进行委托。但仍然不打电话 我的代码在下面是什么地方?
现场代表
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)
}
}
答案 0 :(得分:0)
您是否尝试过在continue userActivity
中实现SceneDelegate
函数:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { }
在使用Firebase DynamicLink时,我遇到了同样的问题,并且看起来UniversalLinks(可能还有其他几个API)在SceneDelegate
上使用了此回调。
因此,如果您要定位的是iOS 13及更低版本,请尝试同时为SceneDelegate
和AppDelegate
实施