为了支持应用程序图标上的快捷方式项目,我们在中实现了以下方法SceneDelegate
:
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)
当应用程序被终止并通过此类快捷方式启动时,不会调用此方法(它只显示主屏幕)。但是,当应用程序在后台运行时,会调用此方法并且一切都会按预期工作。
我也检查过AppDelegate
in didFinishLaunchingWithOptions
查看是否有快捷方式项launchingOptions
但他们是nil
.
检查快捷方式项
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let shortcutItem = connectionOptions.shortcutItem {
shortcutItemToProcess = shortcutItem
}
}
然后处理它
func sceneDidBecomeActive(_ scene: UIScene) {
if let shortcutItem = shortcutItemToProcess {
shortcutItemToProcess = nil
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)