[英]Xcode 13 Universal Links for both iOS 13+ and 12
我有一个支持分钟的应用程序。 iOS 9. 但是,我正在考虑支持 min。 iOS 12(我知道最好的做法是已经支持 min n-2)
在这个应用程序中,我没有SceneDelegate
但只有AppDelegate
。 我正在尝试在我的 iOS 15 真实设备上打开通用链接。
另外,我知道下面的一些AppDelegate
函数在 iOS 13+ 设备上不起作用。
application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
而不是AppDelegate
,我已经知道,我应该使用SceneDelegate
的以下 function:
scene(_ scene: UIScene, continue userActivity: NSUserActivity)
我的SceneDelegate
willConnectTo
,如下所示:
guard let _ = (scene as? UIWindowScene) else { return }
let viewController = Storyboard.launchScreen.instantiate(from: .main)
if let windowScene = scene as? UIWindowScene {
self.window = UIWindow(windowScene: windowScene)
self.window?.rootViewController = viewController
self.window?.makeKeyAndVisible()
}
(此外,上面的生根代码在AppDelegate
的didFinishLaunchingWithOptions
中实现)
但是,当我将所有 SceneDelegate 功能实现到我的应用程序时,我在第一次启动时看到一个黑色空白屏幕。
我收到这些日志:
[SceneConfiguration] Info.plist configuration "Default Configuration" for
UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key,
但无法加载名称为“My_APP.SceneDelegate”的 class。
[SceneConfiguration] Info.plist configuration "(no name)" for
UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key,
but could not load class with name "My_APP.SceneDelegate".
到目前为止,我为通用链接做了什么?
(以上步骤在 Xcode 和developer.apple.com中自动创建 Debug/Release.entitlements )
Main.storyboard
。Info.plist
如下所示:<key>UIApplicationSceneManifest</key>
<dict>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneDelegateClassName</key>
<string>$(PROJECT_MODULE_NAME).SceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
</dict>
还有我的apple-app-site-association
文件:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "*****.com.*****.******",
"paths": [
"/",
"/titles",
"/title/*",
"/search"
]
}
]
}
}
在解决方案上花了 2 周后,我做了以下事情:
这与添加SceneDelegate
。 因此,如果您的应用中没有任何多场景场景,则无需添加SceneDelegate
。
open func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = Storyboard.launchScreen.instantiate(from: .main)
window?.makeKeyAndVisible()
handleDeepLink()
migrateLoginDetails()
.andThen(updateConfiguration)
.andThen(updateTitles)
.subscribe { [unowned self] _ in
Theme.apply()
let rootViewController = Storyboard.main.instantiate()
self.window?.rootViewController = rootViewController
self.didSetWindowRootViewController.onNext(rootViewController)
Updater.sharedInstance().showUpdateWithConfirmation(in: rootViewController)
}
.disposed(by: disposeBag)
}
处理 DeepLinks 以打开相应的 URL:
private func handleDeepLink() {
shouldHandleLink
.flatMap { [didSetWindowRootViewController] url in
didSetWindowRootViewController.map { ($0, url) }
}
.observe(on: MainScheduler.instance)
.subscribe(onNext: { vc, url in
URLHandler.shared.open(url: url, from: vc)
})
.disposed(by: disposeBag)
}
更新 AppDelegate 中的didFinishLaunching
方法后, userActivity
方法不再调用。
public func application(_: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler _: @escaping
([UIUserActivityRestoring]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL else {
return false
}
shouldHandleLink.onNext(incomingURL)
return true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.