skip to Main Content

I have a static quick action with the following setup.

Setup quick action

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

enter image description here

enter image description here


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


  1. replace

    print(">>>> SceneDelegate willConnectTo")
    

    with

    print(connectionOptions.shortcutItem)
    

    and verify if the shortcutItem is being printed correctly

    Login or Signup to reply.
  2. If you are using the default scheme in Xcode, the run command will build and launch automatically…

    Which means, you need:

    If your app is already loaded, the system calls the
    windowScene(_:performActionFor:completionHandler:) function of your
    scene delegate.

    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:)

    Important

    This method is not called for scene-based apps. If you have
    a scene-based app, implement
    windowScene(_:performActionFor:completionHandler:) in your scene
    delegate instead.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search