Ios 使用“handleInApp”时,Siri总是说;对不起,您';“我需要在应用程序中继续”;与不推荐的'continueInApp'不同`

Ios 使用“handleInApp”时,Siri总是说;对不起,您';“我需要在应用程序中继续”;与不推荐的'continueInApp'不同`,ios,sirikit,Ios,Sirikit,我正在尝试将Siri训练意图集成到我的应用程序中。我被奇怪的错误所震惊 class StartWorkOutRequestHandling : NSObject, INStartWorkoutIntentHandling { func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) { if

我正在尝试将Siri训练意图集成到我的应用程序中。我被奇怪的错误所震惊

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 instartworkoutinentresponsecode:Int的定义{

@可用(iOS,引入版本:10.0,不推荐版本:11.0,消息: “iOS上不推荐使用InstartWorkoutinetResponseContinueInApp。 请改用InstartWorkoutinetResponseDeHandleInApp) 案件连续审理

我理解
.handleInApp
在后台打开应用程序,其中as
continueInApp
打开应用程序

但当我使用handleInApp对Siri说“用我的AppName开始训练”时,Siri说

“抱歉,您需要在应用程序中继续”

并提供了一个打开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方法

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

但是它使用了不推荐的continueInApp,所以不能在iOS 11中使用

我在这里犯了什么错误?为什么使用
handleInApp
无法打开应用程序,为什么Siri抱怨我需要在应用程序中继续!如何使用
handleInApp
打开应用程序

如果我在使用锻炼意图时不应该从Siri打开应用程序,我相信也无法为锻炼意图触发
IntentUI
。 参考:


请帮忙。

请检查这张

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);
        }
    }

谢谢你发布答案。我会看一看,然后再回复。现在我已经更新了你的答案:)+1