gpt4 book ai didi

ios - 关于使用 `handleInApp` WorkoutIntentResponseCode Siri 总是说 "Sorry,you' ll need to continue in App“不像弃用的 `continueInApp`

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:12 24 4
gpt4 key购买 nike

我正在尝试将 Siri WorkOut intent 集成到我的应用程序中。我遇到了奇怪的错误。

class StartWorkOutRequestHandling : NSObject, INStartWorkoutIntentHandling {
func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {
if let _ = intent.workoutName {
if #available(iOSApplicationExtension 11.0, *) {
let userActivity = NSUserActivity(activityType: "test")
let response = INStartWorkoutIntentResponse(code: .handleInApp, userActivity: userActivity)
completion(response);
}
else {
// Fallback on earlier versions
let userActivity = NSUserActivity(activityType: "test")
let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
completion(response)
}

}
else {
let response = INStartWorkoutIntentResponse(code: .failureNoMatchingWorkout, userActivity: .none)
completion(response);
}
}
}

正如您在 handle(startWorkout 中看到的那样,我正在检查 iOS 版本是否为 11 或更高版本,如果是,我使用 handleInApp 响应代码,如果不是,我使用 continueInApp .这是因为

public enum INStartWorkoutIntentResponseCode 的定义:Int {

@available(iOS, introduced: 10.0, deprecated: 11.0, message: "INStartWorkoutIntentResponseCodeContinueInApp is deprecated on iOS. Please use INStartWorkoutIntentResponseCodeHandleInApp instead") case continueInApp

我了解 .handleInApp 在后台打开应用程序,而 continueInApp 打开应用程序。

但是当我使用 handleInApp 并对 Siri 说“使用我的 AppName 开始锻炼”时,Siri 说

"Sorry,You'll need to continue in the app"

并提供一个 Open MyApp 按钮。另一方面,如果我简单地使用

    func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {
if let _ = intent.workoutName {
let userActivity = NSUserActivity(activityType: "test")
let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
completion(response);
}
else {
let response = INStartWorkoutIntentResponse(code: .failureNoMatchingWorkout, userActivity: .none)
completion(response);
}
}

忽略警告 Siri 按预期打开应用程序。值得注意的是,在这两种情况下都是

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
//this is a legacy app hence part of code is still in Objective-C
}

app delegates 方法被正确调用。

虽然我在这里发现了类似的问题

Siri always responds 'Continue in the app' when starting workout with SiriKit

但它使用已弃用的 continueInApp。所以不能在 iOS 11 中使用它。

我在这里犯了什么错误?为什么使用 handleInApp 无法打开应用程序以及为什么 Siri 提示我需要在应用程序中继续!如何使用 handleInApp 打开应用。

如果我不应该在使用 Workout 意图时从 Siri 打开应用程序,我相信没有办法触发 IntentUI 也用于 Workout 意图。引用:SiriKit, How to display response for start Workout Intent?

请帮忙。

最佳答案

请检查这个......

func handle(intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {

if let _ = intent.workoutName {
let userActivity = NSUserActivity(activityType: "test")
let response = INStartWorkoutIntentResponse(code: INStartWorkoutIntentResponseCode(rawValue: 2)!, userActivity: userActivity)
completion(response);
}
else {

let response = INStartWorkoutIntentResponse(code: INStartWorkoutIntentResponseCode(rawValue: 6)!, userActivity: .none)
completion(response);
}
}

关于ios - 关于使用 `handleInApp` WorkoutIntentResponseCode Siri 总是说 "Sorry,you' ll need to continue in App“不像弃用的 `continueInApp`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46961441/

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