我通过以下设置进行静态快速操作。
UIApplicationShortcutItemIconSymbolName = "alarm"
UIApplicationShortcutItemType = "com.yocto.xyz.action"
UIApplicationShortcutItemTitle = "Hello"
但是,当我点击它时,以下功能都没有被执行
@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
谢谢你。
更换
print(">>>> SceneDelegate willConnectTo")
与
print(connectionOptions.shortcutItem)
并验证快捷方式项目是否正确打印