JLChen
2021-11-25 dd31df23c4a4b0ab5357014bf822a3704cf21621
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
//  IntentViewController.m
//  HDLSceneSiriUI
//
//  Created by 陈嘉乐 on 2021/11/25.
//
 
#import "IntentViewController.h"
#import "HDLRunSceneIntent.h"
// As an example, this extension's Info.plist has been configured to handle interactions for INSendMessageIntent.
// You will want to replace this or add other intents as appropriate.
// The intents whose interactions you wish to handle must be declared in the extension's Info.plist.
 
// You can test this example integration by saying things to Siri like:
// "Send a message using <myApp>"
 
@interface IntentViewController ()
 
@end
 
@implementation IntentViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
 
#pragma mark - INUIHostedViewControlling
 
// Prepare your view controller for the interaction to handle.
- (void)configureViewForParameters:(NSSet <INParameter *> *)parameters ofInteraction:(INInteraction *)interaction interactiveBehavior:(INUIInteractiveBehavior)interactiveBehavior context:(INUIHostedViewContext)context completion:(void (^)(BOOL success, NSSet <INParameter *> *configuredParameters, CGSize desiredSize))completion {
    // Do configuration here, including preparing views and calculating a desired size for presentation.
    if (@available(iOS 12.0, *)) {
        HDLRunSceneIntentResponse *rsp = (HDLRunSceneIntentResponse *) interaction.intentResponse;
        
//        HDLRunSceneIntent *intent = (HDLRunSceneIntent *)interaction.intent;
        NSLog(@"HDL code:%ld s:%@ e:%@",(long)rsp.code,rsp.successMessage,rsp.errorMessage);
        //    self.messageLabel.hidden = NO;
        if (rsp.code == HDLRunSceneIntentResponseCodeSuccess) {
            self.messageLabel.text = [NSString stringWithFormat: @"%@",rsp.successMessage];
        }else if (rsp.code == HDLRunSceneIntentResponseCodeFailure || rsp.code == HDLRunSceneIntentResponseCodeError) {
            self.messageLabel.text = [NSString stringWithFormat: @"%@",rsp.errorMessage];
        }else{
            self.messageLabel.text = [NSString stringWithFormat: @"%@",rsp.successMessage];
        }
    } else {
        // Fallback on earlier versions
    }
    CGSize size = CGSizeMake([self desiredSize].width, 80);
    if (completion) {
        completion(YES, parameters, size);
    }
}
 
- (CGSize)desiredSize {
    return [self extensionContext].hostedViewMaximumAllowedSize;
}
 
@end