Instance Method

application(_:performActionFor:completionHandler:)

Called when the user selects a Home screen quick action for your app, except when you’ve intercepted the interaction in a launch method.

Declaration

optional func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)

Parameters

application

Your shared app object.

shortcutItem

The quick action for which you are providing an implementation in this method.

completionHandler

Call this block after your quick action implementation completes, returning true or false depending on the success or failure of your implementation code.

succeeded

A Boolean value indicating whether or not your implementation succeeded.

Discussion

Implement this method to respond to the user’s selection of a Home screen quick action for your app; call the completion handler, with an appropriate Boolean value, when finished.

It’s your responsibility to ensure the system calls this method conditionally, depending on whether or not one of your app launch methods (application(_:willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions:)) has already handled a quick action invocation. The system calls a launch method (before calling this method) when a user selects a quick action for your app and your app launches instead of activating.

The requested quick action might employ code paths different than those used otherwise when your app launches. For example, say your app normally launches to display view A, but your app was launched in response to a quick action that needs view B. To handle such cases, check, on launch, whether your app is being launched via a quick action. Perform this check in your application(_:willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions:) method by checking for the shortcutItem launch option key. The UIApplicationShortcutItem object is available as the value of the launch option key.

If you find that your app was indeed launched using a quick action, perform the requested quick action within the launch method and return a value of false from that method. When you return a value of false, the system does not call the application:performActionForShortcutItem:completionHandler: method.