【发布时间】:2017-08-05 16:12:15
【问题描述】:
我正在学习 SiriKit,但我遇到了一个大问题。我构建了一个应用程序,有时他工作,有时他不工作。我想打开一个特定的控制器而不说“开始苹果运动”或类似的东西。我用户锻炼,因为它是最简单的,我想知道我是否只能说“通过 MyApp 打开个人资料”。这可能吗?
这是我的代码:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard let intent = userActivity.interaction?.intent as? INStartWorkoutIntent else {
print("AppDelegate: Start Workout Intent - FALSE")
return false
}
print("AppDelegate: Start Workout Intent - TRUE")
print("INTENT: ", intent)
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let spokenPhrase = intent.workoutName?.spokenPhrase else {
return false
}
switch spokenPhrase {
case "test":
let vc = storyboard.instantiateViewController(withIdentifier: "firstVC")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
case "apple":
let vc = storyboard.instantiateViewController(withIdentifier: "secondVC")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
default:
break
}
return true
}
【问题讨论】: