Siri – 联系人search行为类似于Skype的audio通话

我正在实施一个VoIP应用程序,我需要通过Siri发起呼叫。 我能够通过Siri发起一个呼叫。 但问题是 – 每次启动应用程序时,虽然联系人不在应用程序的联系人列表中。

我不知道如何以及在哪里处理。 我的意思是不启动应用程序,如果应用程序没有像Skype处理它的联系。 Skype回复如下:

嗯,Skype没有find<user>。

你想打给谁?

Bellow是扩展处理程序的代码片段:

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

您可以在resolveContactsForStartAudioCall方法中处理该问题,检查您在该意图中获得的人是否包含在您的应用程序联系人列表中。

 - (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 } 

请注意,如果您想要将应用程序中的联系人分享给任何分机,您可能需要启用应用程序组支持。 以下是一些指导方针:

  1. 苹果文件
  2. 堆栈溢出链接