问题
To support shortcut items on the app icon we've implemented the following method in SceneDelegate
:
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)
This method does not get called when the app is killed and launched through such an shortcut item (it just shows the main screen). However when the app is running and in the background this method gets called and everything works as expected.
I've also checked AppDelegate
in didFinishLaunchingWithOptions
to see whether there's a shortcut item in launchingOptions
but they are nil
.
回答1:
Check for shortcutItem in
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let shortcutItem = connectionOptions.shortcutItem {
shortcutItemToProcess = shortcutItem
}
}
and then handle it in
func sceneDidBecomeActive(_ scene: UIScene) {
if let shortcutItem = shortcutItemToProcess {
shortcutItemToProcess = nil
}
}
来源:https://stackoverflow.com/questions/58134706/shortcut-item-on-app-icon-not-working-with-ios-13