我可以从 Siri 成功启动我的应用程序,但我在调试器中收到了 NSUserActivity 消息。我不记得在以前的版本中看到过该消息,但也许我没有注意。我错过了什么?有什么我应该从堆栈中弹出的东西吗?设置一些标志?
(我只能在设备上启动应用程序,而不是在模拟器中,但这是另一天的问题。Siri 告诉我出了点问题,然后再试一次。)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType != "com.mydomain.myactivity" {
os_log("The app was called with an invalid activityType")
return false
}
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = self.window!.rootViewController as! UITabBarController
tabBarController.tabBar.barTintColor = UIColor(red: 184.0/255.0, green: 64.0/255.0, blue: 37.0/255.0, alpha: 0.2)
guard let tabVCs = tabBarController.viewControllers else {
os_log("restorationHandler: Can't get tabVCs")
return false
}
guard let myTargetViewController = mainStoryboard.instantiateViewController(withIdentifier: "myTargetViewController") as? MyTargetViewController else {
os_log("restorationHandler: Can't get myTargetViewController from storyboard")
return false
}
guard let tab1NavViewController = tabVCs[0] as? UINavigationController else {
os_log("restorationHandler: Can't get tab1NavViewController from tabVCs")
return false
}
tabBarController.selectedIndex = 0
myTargetViewController.calledFromShortcut = true
tab1NavViewController.pushViewController(myTargetViewController, animated: true)
return true
}