我正在尝试使用Siri快捷方式介绍特定的ViewController。步骤是:
在Info.plist中,我创建了一个行“ NSUserActivityTypes”数组。项目0为com.testSiriShortcut.makePresent
我为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。在设置中,我打开“显示最近的快捷方式”和“在锁定屏幕上显示捐赠”