0
我正在學習SiriKit,我有一個很大的問題。我建立了一個應用程序,有時他工作,有時他不工作。我想打開一個特定的控制器,而不用說「開始蘋果運動」或類似的東西。我用戶鍛鍊,因爲它是最簡單的,我想知道我是否只能說「通過MyApp打開個人資料」。那可能嗎?如何用Siri打開/觸發視圖控制器?
這裏是我的代碼:
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
}
謝謝你,我想我會用Speech Framework。 –