为什么快速操作没有触发任何应用功能?

问题描述 投票:0回答:1

我通过以下设置进行静态快速操作。

设置快速操作

UIApplicationShortcutItemIconSymbolName = "alarm"
UIApplicationShortcutItemType = "com.yocto.xyz.action"
UIApplicationShortcutItemTitle = "Hello"

enter image description here

enter image description here


但是,当我点击它时,以下功能都没有被执行

@main
class AppDelegate: UIResponder, UIApplicationDelegate {



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        print(">>>> AppDelegate didFinishLaunchingWithOptions")
        return true
    }

    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        print(">>>> AppDelegate shortcutItem.type \(shortcutItem.type)")
        
        completionHandler(true)
    }

    ...

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }
        
        print(">>>> SceneDelegate willConnectTo")
    }

我可以知道哪里出了问题吗?我还可能错过什么?

这是一个演示该问题的演示项目:https://github.com/yccheok/quick-action-not-working

谢谢你。

ios swift uikit
1个回答
0
投票

更换

print(">>>> SceneDelegate willConnectTo")

print(connectionOptions.shortcutItem)

并验证快捷方式项目是否正确打印

© www.soinside.com 2019 - 2024. All rights reserved.