How do I check if my app is resumed by a Siri shortcut

青春壹個敷衍的年華 提交于 2021-02-11 14:37:57

问题


I am working with Siri shortcuts. I wanted to know if my app is launched from a Siri shortcut in the following cases:

  1. When the application is running in the background
  2. When the application is not running in the background

For case 2, I can use the "didFinishLaunchingWithOptions" method but for case 1, I am not sure what approach to use.

I would appreciate any suggestions and thoughts on this topic. Thank you.


回答1:


You can implement this check in your AppDelegate

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if #available(iOS 12.0, *) {
        if userActivity.interaction?.intent is {YOUR_INTENT_CLASS} {
            // App launched via that particular shortcut.
        }
    }
}


来源:https://stackoverflow.com/questions/57142191/how-do-i-check-if-my-app-is-resumed-by-a-siri-shortcut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!