How to use dynamic quick action in swift?
i am able to trigger my methods if the app is in multitasking. but if the app isn't running in background it doesn't work.
i am setting up my quick actions in applicationWillResignActive / sceneWillResignActive.
i am handling my methods in:
"func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)"
and
"func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)"
any suggestions?
The performActionFor method is only called when the app is running (in the background0. If it is not you need to check for shortcuts when the app starts in the didFinishLaunchingWithOptions or willFinishLaunchingWithOptions. The shortcut item will be in the launch items.
Something like this:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if let shotcutItem = launchOptions?[UIApplication.LaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem{
handleShortcutItem(shortcutItem)
}
return true
}
Obviously the handleShortcutItem
is a method that will actually process the shortcut and do what you want. You should be able to use the same one for both cases.