JLChen
2021-11-26 f26dfd48aa7bf4c194863cc3b3f47d38bc8a2d57
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
//  IntentHandler.m
//  HDLSceneSiri
//
//  Created by 陈嘉乐 on 2021/11/25.
//
 
#import "IntentHandler.h"
#import "HDLRunSceneIntent.h"
#import "HDLSceneHandler.h"
 
// As an example, this class is set up to handle Message intents.
// You will want to replace this or add other intents as appropriate.
// The intents you wish to handle must be declared in the extension's Info.plist.
 
// You can test your example integration by saying things to Siri like:
// "Send a message using <myApp>"
// "<myApp> John saying hello"
// "Search for messages in <myApp>"
 
@interface IntentHandler ()
 
@end
 
@implementation IntentHandler
 
- (id)handlerForIntent:(INIntent *)intent {
    // This is the default implementation.  If you want different objects to handle different intents,
    // you can override this and return the handler you want for that particular intent.
    if (@available(iOS 12.0, *)) {
        if ([intent isKindOfClass:[HDLRunSceneIntent class]]) {
            return [[HDLSceneHandler alloc] init];
        }
    }
    
    return self;
}
//
//#pragma mark - INSendMessageIntentHandling
//
//// Implement resolution methods to provide additional information about your intent (optional).
//- (void)resolveRecipientsForSendMessage:(INSendMessageIntent *)intent with:(void (^)(NSArray<INSendMessageRecipientResolutionResult *> *resolutionResults))completion {
//    NSArray<INPerson *> *recipients = intent.recipients;
//    // If no recipients were provided we'll need to prompt for a value.
//    if (recipients.count == 0) {
//        completion(@[[INSendMessageRecipientResolutionResult needsValue]]);
//        return;
//    }
//    NSMutableArray<INSendMessageRecipientResolutionResult *> *resolutionResults = [NSMutableArray array];
//    
//    for (INPerson *recipient in recipients) {
//        NSArray<INPerson *> *matchingContacts = @[recipient]; // Implement your contact matching logic here to create an array of matching contacts
//        if (matchingContacts.count > 1) {
//            // We need Siri's help to ask user to pick one from the matches.
//            [resolutionResults addObject:[INSendMessageRecipientResolutionResult disambiguationWithPeopleToDisambiguate:matchingContacts]];
//
//        } else if (matchingContacts.count == 1) {
//            // We have exactly one matching contact
//            [resolutionResults addObject:[INSendMessageRecipientResolutionResult successWithResolvedPerson:recipient]];
//        } else {
//            // We have no contacts matching the description provided
//            [resolutionResults addObject:[INSendMessageRecipientResolutionResult unsupported]];
//        }
//    }
//    completion(resolutionResults);
//}
//
//- (void)resolveContentForSendMessage:(INSendMessageIntent *)intent withCompletion:(void (^)(INStringResolutionResult *resolutionResult))completion {
//    NSString *text = intent.content;
//    if (text && ![text isEqualToString:@""]) {
//        completion([INStringResolutionResult successWithResolvedString:text]);
//    } else {
//        completion([INStringResolutionResult needsValue]);
//    }
//}
//
//// Once resolution is completed, perform validation on the intent and provide confirmation (optional).
//
//- (void)confirmSendMessage:(INSendMessageIntent *)intent completion:(void (^)(INSendMessageIntentResponse *response))completion {
//    // Verify user is authenticated and your app is ready to send a message.
//    
//    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INSendMessageIntent class])];
//    INSendMessageIntentResponse *response = [[INSendMessageIntentResponse alloc] initWithCode:INSendMessageIntentResponseCodeReady userActivity:userActivity];
//    completion(response);
//}
//
//// Handle the completed intent (required).
//
//- (void)handleSendMessage:(INSendMessageIntent *)intent completion:(void (^)(INSendMessageIntentResponse *response))completion {
//    // Implement your application logic to send a message here.
//    
//    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INSendMessageIntent class])];
//    INSendMessageIntentResponse *response = [[INSendMessageIntentResponse alloc] initWithCode:INSendMessageIntentResponseCodeSuccess userActivity:userActivity];
//    completion(response);
//}
//
//// Implement handlers for each intent you wish to handle.  As an example for messages, you may wish to also handle searchForMessages and setMessageAttributes.
//
//#pragma mark - INSearchForMessagesIntentHandling
//
//- (void)handleSearchForMessages:(INSearchForMessagesIntent *)intent completion:(void (^)(INSearchForMessagesIntentResponse *response))completion {
//    // Implement your application logic to find a message that matches the information in the intent.
//    
//    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INSearchForMessagesIntent class])];
//    INSearchForMessagesIntentResponse *response = [[INSearchForMessagesIntentResponse alloc] initWithCode:INSearchForMessagesIntentResponseCodeSuccess userActivity:userActivity];
//    // Initialize with found message's attributes
//    response.messages = @[[[INMessage alloc]
//        initWithIdentifier:@"identifier"
//        content:@"I am so excited about SiriKit!"
//        dateSent:[NSDate date]
//        sender:[[INPerson alloc] initWithPersonHandle:[[INPersonHandle alloc] initWithValue:@"sarah@example.com" type:INPersonHandleTypeEmailAddress] nameComponents:nil displayName:@"Sarah" image:nil contactIdentifier:nil customIdentifier:nil]
//        recipients:@[[[INPerson alloc] initWithPersonHandle:[[INPersonHandle alloc] initWithValue:@"+1-415-555-5555" type:INPersonHandleTypePhoneNumber] nameComponents:nil displayName:@"John" image:nil contactIdentifier:nil customIdentifier:nil]]
//    ]];
//    completion(response);
//}
//
//#pragma mark - INSetMessageAttributeIntentHandling
//
//- (void)handleSetMessageAttribute:(INSetMessageAttributeIntent *)intent completion:(void (^)(INSetMessageAttributeIntentResponse *response))completion {
//    // Implement your application logic to set the message attribute here.
//    
//    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INSetMessageAttributeIntent class])];
//    INSetMessageAttributeIntentResponse *response = [[INSetMessageAttributeIntentResponse alloc] initWithCode:INSetMessageAttributeIntentResponseCodeSuccess userActivity:userActivity];
//    completion(response);
//}
 
@end