【问题标题】:How to open/trigger a view controller with Siri?如何使用 Siri 打开/触发视图控制器?
【发布时间】: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
}

【问题讨论】:

    标签: ios swift sirikit


    【解决方案1】:

    不,这是不可能的。 SiriKit 只能在非常具体的场景中使用。由于Siri 与自然语言处理一起工作,它需要“听”文本中的某些特定单词才能将它们解码为Swift 对象。对于每个Intent,都有一些特定的关键字需要说明,否则Siri 不会将用户输入识别为特定的Intent

    即使您会“破解”您的应用,使其执行与锻炼完全无关的操作并使用锻炼意图从Siri 打开它,您的应用也很可能会被AppStore 拒绝。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多