gpt4 book ai didi

ios - Siri - 联系人搜索行为类似于 Skype 的音频通话

转载 作者:可可西里 更新时间:2023-11-01 04:55:50 25 4
gpt4 key购买 nike

我正在实现一个 VoIP 应用程序,我需要在其中通过 Siri 发起调用。我能够通过 Siri 发起调用。但问题是 - 每次启动应用程序时,尽管联系人不在应用程序的联系人列表中。

我不确定如何以及在哪里处理它。我的意思是如果应用程序没有像 Skype 那样处理它的联系人,则不要启动该应用程序。 Skype 回复如下:

Hmm, Skype didn't find <user>.

Who would you like to call?

下面是我的扩展处理程序代码片段:

- (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. Apple Document
  2. Stack Overflow link

关于ios - Siri - 联系人搜索行为类似于 Skype 的音频通话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41436004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com