gpt4 book ai didi

ios - 使用 SiriKit 开始锻炼时,Siri 始终响应 'Continue in the app'

转载 作者:行者123 更新时间:2023-11-28 08:27:46 24 4
gpt4 key购买 nike

我正在为我们的应用开发一个 SiriKit intents 扩展。我们正在使用锻炼扩展类型。问题是,我只是将所需的方法放入并始终传递 .ready 但 Siri 始终响应,

Sorry, you'll have to continue in the app.

我也尝试了其他响应(.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。

感谢您的回复。

最佳答案

一旦您准备好在您的应用中开始锻炼,您需要使用 .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)
}

查看文档:

Your extension is ready to transfer control to the app so that the workout can be started. Upon returning this code, SiriKit launches your app and passes it the NSUserActivity object you provided at initialization time. (If you did not provide a user activity object, SiriKit creates one for you.) SiriKit adds an INInteraction object with the intent and your response to the user activity object before delivering it. Your app should use the information in the user activity object to start the workout.

关于ios - 使用 SiriKit 开始锻炼时,Siri 始终响应 'Continue in the app',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39571359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com