使用快捷方式

时间:2018-07-07 16:49:40

标签: swift siri

我正在尝试使用Siri快捷方式介绍特定的ViewController。步骤是:

  1. 在Info.plist中,我创建了一个行“ NSUserActivityTypes”数组。项目0为com.testSiriShortcut.makePresent

  2. 我为Activity创建了方法,在viewDidload()中调用

    func activity(){
    let activity = NSUserActivity(activityType: "com.testSiriShortcut.makePresent")
    activity.title = "Make View Red"
    activity.userInfo = ["present" : "Controller"]
    activity.isEligibleForSearch = true
    activity.isEligibleForPrediction = true
    activity.persistentIdentifier = NSUserActivityPersistentIdentifier(rawValue: "com.testSiriShortcut.makePresent")
    activity.suggestedInvocationPhrase = "View Page"
    self.userActivity = activity
    activity.becomeCurrent()
    

3。在AppDelage中

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

    let viewController = window?.rootViewController as! ViewController
    viewController.changeColor()
    return true
}

4。在设置中,我打开“显示最近的快捷方式”和“在锁定屏幕上显示捐赠”

1 个答案:

答案 0 :(得分:0)

不要忘记在项目设置的功能部分中启用Siri。

enter image description here