//
|
// HDLSceneHandler.m
|
// HDLSceneSiri
|
//
|
// Created by 陈嘉乐 on 2021/11/25.
|
//
|
|
#import "HDLSceneHandler.h"
|
|
@implementation HDLSceneHandler
|
|
// 该方法是在 siri 匹配到相应的 Intent 时候调用。
|
// 如果用失败的方法初始化HDLRunSceneIntentResponse,在匹siri后就会报错
|
// 不管用哪个成功的方式,只是初始化参数的值而已,都一样
|
// 此为第一道拦截,如果code设置为失败或者打开app,那就直接失败/跳走了,连展示界面的机会都没有
|
// 所以一半这里就直接返回成功,让siri继续往下走,打开界面
|
// 建议:只用reday和success 这两个code
|
- (void)confirmRunScene:(HDLRunSceneIntent *)intent completion:(void (^)(HDLRunSceneIntentResponse *response))completion NS_SWIFT_NAME(confirm(intent:completion:)){
|
|
|
|
HDLRunSceneIntentResponse *rsp = [[HDLRunSceneIntentResponse alloc] initWithCode:HDLRunSceneIntentResponseCodeInProgress userActivity:nil];
|
rsp.successMessage =@"请等待...";
|
completion(rsp);
|
}
|
|
- (void)handleHDLRunScene:(nonnull HDLRunSceneIntent *)intent completion:(nonnull void (^)(HDLRunSceneIntentResponse * _Nonnull))completion {
|
NSLog(@"HDL handleRunScene");
|
NSString *text = @"执行成功";
|
|
|
NSData *jsonData = [intent.controlJSONStr dataUsingEncoding:NSUTF8StringEncoding];
|
NSError *error;
|
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
|
if (error) {
|
//解析出错
|
}
|
NSLog(@"dic :%@",dic);
|
text = [NSString stringWithFormat:@"%@ %@",text,intent.controlJSONStr];
|
|
|
//执行成功
|
HDLRunSceneIntentResponse *rsp = [[HDLRunSceneIntentResponse alloc] initWithCode:HDLRunSceneIntentResponseCodeSuccess userActivity:nil];
|
rsp.controlName = intent.controlName;
|
rsp.successMessage = text;
|
completion(rsp);
|
|
}
|
|
|
@end
|