I have a static quick action with the following setup.
Setup quick action
UIApplicationShortcutItemIconSymbolName = "alarm"
UIApplicationShortcutItemType = "com.yocto.xyz.action"
UIApplicationShortcutItemTitle = "Hello"
However, when I tap on it, none of the following function is executed
@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")
}
May I know what could have gone wrong? What else might I be missing?
Here’s a demo project to demonstrate the issue: https://github.com/yccheok/quick-action-not-working
Thank you.
2
Answers
replace
with
and verify if the shortcutItem is being printed correctly
If you are using the default scheme in Xcode, the run command will build and launch automatically…
Which means, you need:
https://developer.apple.com/documentation/uikit/menus_and_shortcuts/add_home_screen_quick_actions#3701696
And if you look at the docs for
application(_:performActionFor:completionHandler:)
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622935-application#discussion
NOTE: You do eventually need to make both code paths work, so you will want to have a non-launch scheme so you can test the other scene code path, but I’m mostly interested in trying to answer your immediate question.