Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

ios - Siri - contact searching behaviour similar to skype for audio call

I am implementing a VoIP application where I need to initiate call through Siri. I was able to initiate a call through Siri. But problem is - every time application is launched though the contact is not in the app's contact list.

I am not sure how and where to handle that. I mean not to launch the application if application does not have that contact like Skype handled it. Skype replied something like:

Hmm, Skype didn't find <user>.

Who would you like to call?

Bellow is my code snippet for the Extension handler:

- (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.
    return self;
}

#pragma mark - INStartAudioCallIntentHandling

- (void)resolveContactsForStartAudioCall:(INStartAudioCallIntent *)intent
                          withCompletion:(void (^)(NSArray<INPersonResolutionResult *> *resolutionResults))completion{
    NSArray<INPerson *> *recipients = intent.contacts;
    NSMutableArray<INPersonResolutionResult *> *resolutionResults = [NSMutableArray array];
    if (recipients.count == 0) {
        completion(@[[INPersonResolutionResult needsValue]]);
        return;
    }else if(recipients.count==1){
        [resolutionResults addObject:[INPersonResolutionResult successWithResolvedPerson:recipients.firstObject]];
    }else if(recipients.count>1){
        [resolutionResults addObject:[INPersonResolutionResult disambiguationWithPeopleToDisambiguate:recipients]];
    }else{
        [resolutionResults addObject:[INPersonResolutionResult unsupported]];
    }
    completion(resolutionResults);
}

- (void)confirmStartAudioCall:(INStartAudioCallIntent *)intent
                   completion:(void (^)(INStartAudioCallIntentResponse *response))completion{
    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INStartAudioCallIntent class])];
    INStartAudioCallIntentResponse *response = [[INStartAudioCallIntentResponse alloc] initWithCode:INStartAudioCallIntentResponseCodeReady userActivity:userActivity];
    completion(response);
}

- (void)handleStartAudioCall:(INStartAudioCallIntent *)intent
                  completion:(void (^)(INStartAudioCallIntentResponse *response))completion{
    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INStartAudioCallIntent class])];
    INStartAudioCallIntentResponse *response = [[INStartAudioCallIntentResponse alloc] initWithCode:INStartAudioCallIntentResponseCodeContinueInApp userActivity:userActivity];
    completion(response);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can handle that in resolveContactsForStartAudioCall method, check that the person you get in that intent contains in your app contact list.

- (void)resolveContactsForStartAudioCall:(INStartAudioCallIntent *)intent
                              withCompletion:(void (^)(NSArray<INPersonResolutionResult *> *resolutionResults))completion{
        NSArray<INPerson *> *recipients = intent.contacts;
        NSMutableArray<INPersonResolutionResult *> *resolutionResults = [NSMutableArray array];
        if (recipients.count == 0) {
            completion(@[[INPersonResolutionResult needsValue]]);
            return;
        }else if(recipients.count==1){
            if([self containContact:recipients.firstObject.displayName]){
               [resolutionResults addObject:[INPersonResolutionResult successWithResolvedPerson:recipients.firstObject]];
            }else [resolutionResults addObject:[INPersonResolutionResult unsupported]];
        }else if(recipients.count>1){
            [resolutionResults addObject:[INPersonResolutionResult disambiguationWithPeopleToDisambiguate:recipients]];
        }else{
            [resolutionResults addObject:[INPersonResolutionResult unsupported]];
        }
        completion(resolutionResults);
}
- (BOOL)containContact:(NSString *)displayName {
           //fetch contacts and check, if exist retun YES else NO
}

Please note you may need to enable App Group support if you want to share contacts from your application to any extension. Here are some guidelines:

  1. Apple Document
  2. Stack Overflow link

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...