Siri总是在应用程序中回复“继续”。在与SiriKit开始锻炼时

时间:2016-09-19 10:51:17

标签: ios iphone swift sirikit intents-extension

我正在为我们的应用开发SiriKit Intent扩展程序。我们正在使用锻炼扩展类型。问题是,我只是将所需的方法放入并且总是通过.ready,但Siri总是回应,

  

抱歉,您必须继续使用该应用。

我也尝试了其他回复(.failure.unspecified),但她仍然说要继续使用该应用。我已按照Apple提供的文档来设置我的.plist文件,但它仍可能与此相关。

这是我的意图代码:

class IntentHandler: INExtension, INStartWorkoutIntentHandling, INPauseWorkoutIntentHandling, INResumeWorkoutIntentHandling, INCancelWorkoutIntentHandling, INEndWorkoutIntentHandling {


override func handler(for intent: INIntent) -> Any {
    // This is the default implementation.  If you want different objects to handle different intents,
    // you can override this and return the handler you want for that particular intent.

    return self
}

func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {
    print("Starting Service")
    let activity = NSUserActivity(activityType: "start_service")
    let result = INStartWorkoutIntentResponse(code: .ready, userActivity: activity)
    completion(result)
}

func handle(endWorkout intent: INEndWorkoutIntent, completion: @escaping (INEndWorkoutIntentResponse) -> Void) {
    print("Ending Service")
    let result = INEndWorkoutIntentResponse(code: .ready, userActivity: nil)
    completion(result)
}

func handle(pauseWorkout intent: INPauseWorkoutIntent, completion: @escaping (INPauseWorkoutIntentResponse) -> Void) {
    print("Pausing Service")
    let result = INPauseWorkoutIntentResponse(code: .ready, userActivity: nil)
    completion(result)
}

func handle(cancelWorkout intent: INCancelWorkoutIntent, completion: @escaping (INCancelWorkoutIntentResponse) -> Void) {
    print("Cancel Service")
    let result = INCancelWorkoutIntentResponse(code: .ready, userActivity: nil)
    completion(result)
}

func handle(resumeWorkout intent: INResumeWorkoutIntent, completion: @escaping (INResumeWorkoutIntentResponse) -> Void) {
    print("Resume Service")
    let result = INResumeWorkoutIntentResponse(code: .ready, userActivity: nil)
    completion(result)
}
}

我尝试了一个断点,在那里处理了开始训练意图,它确实击中了这个功能。我也尝试将.ready传递给INMessageIntent,而Siri在应用程序中没有说开放就做出了回应。我想知道锻炼扩展是否总是如此。如果是的话,我仍然希望Siri能够展示我的IntentsUI。

感谢您的回复。

1 个答案:

答案 0 :(得分:0)

准备好在应用中开始锻炼后,您需要使用.continueInApp

调用完成处理程序

这就像是:

public func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Swift.Void) {
    let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent.self))
    let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
    completion(response)
}

参见文档:

  

您的扩展程序已准备好将控制权转移到应用程序,以便可以开始锻炼。返回此代码后,SiriKit将启动您的应用程序并将其传递给您在初始化时提供的NSUserActivity对象。 (如果您没有提供用户活动对象,SiriKit会为您创建一个。)SiriKit会在交付之前添加一个INInteraction对象,其中包含intent和您对用户活动对象的响应。您的应用应使用用户活动对象中的信息开始锻炼。