如何 open/trigger 带有 Siri 的视图控制器?
How to open/trigger a view controller with Siri?
我正在研究SiriKit,但遇到了一个大问题。我构建了一个应用程序,有时他工作,有时他不工作。我想打开一个特定的控制器而不说 "Start apple exercise" 或类似的东西。我使用 workout 是因为它是最简单的,我想知道我是否只能说 "Open profile via 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
}
不,那是不可能的。 SiriKit
只能在真正特定的场景中使用。由于 Siri
与自然语言处理一起工作,它需要 "listen to" 文本中的某些特定单词才能将其解码为 Swift
对象。每个 Intent
都需要说出一些特定的关键字,否则 Siri
不会将用户输入识别为特定的 Intent
.
即使您 "hack" 您的应用会做一些与锻炼完全无关的事情并使用锻炼意图从 Siri
打开它,您的应用很可能会被 AppStore
拒绝。
我正在研究SiriKit,但遇到了一个大问题。我构建了一个应用程序,有时他工作,有时他不工作。我想打开一个特定的控制器而不说 "Start apple exercise" 或类似的东西。我使用 workout 是因为它是最简单的,我想知道我是否只能说 "Open profile via 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
}
不,那是不可能的。 SiriKit
只能在真正特定的场景中使用。由于 Siri
与自然语言处理一起工作,它需要 "listen to" 文本中的某些特定单词才能将其解码为 Swift
对象。每个 Intent
都需要说出一些特定的关键字,否则 Siri
不会将用户输入识别为特定的 Intent
.
即使您 "hack" 您的应用会做一些与锻炼完全无关的事情并使用锻炼意图从 Siri
打开它,您的应用很可能会被 AppStore
拒绝。