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

标签 ios sirikit

我正在尝试将 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/

相关文章:

ios - didSelectRowAtIndexPath 没有被调用

ios - 子 ViewControllers 数组在具有各种容器的 View Controller 中是否具有特定顺序?

ios - SIRI 不会根据提供的参数回复,而是打开 "Shortcut"应用程序

ios - AWS s3 上传 + api 耗时太长

ios - 如何让 UIAlertView 自动消失?

ios - Siri 在现有项目中不起作用

ios - watchOS 是否支持自定义 SiriKit Intents 的语音快捷方式?

ios - Siri - 联系人搜索行为类似于 Skype 的音频通话

ios - 插页式广告后更改场景 (SpriteKit)

ios - Siri 支持 : What are supported intent parameters for INPlayMediaIntent?