Shortcut item on app icon not working with iOS 13

我是研究僧i 提交于 2020-01-05 04:17:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!