2017-01-04 8 views
-26

Я реализую приложение VoIP, где мне нужно инициировать вызов через Siri. Я смог инициировать звонок через Сири. Но проблема в том, что каждый раз, когда приложение запускается, хотя контакт отсутствует в списке контактов приложения.Siri - контактное поведение, похожее на skype для аудиовызова

Я не уверен, как и где обращаться с этим. Я имею в виду не запускать приложение, если у приложения нет такого контакта, как Skype. Skype ответил что-то вроде:

Хмм, Skype не нашёл < пользователь>.

Кому вы хотели бы позвонить?

пыльник мой фрагмент кода для обработчика Extension:

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

Обсуждаемые [на Meta] (http://meta.stackoverflow.com/questions/340839/user-answers-a-question-of пользователь свой-чужой-и-просит-The-же-вопрос-опять-уже? центибар = 1). Я думаю, мы можем остановить downvoting. –

+0

@ThomasWeller благодарит вас за ответ. я попытался дать понять на мета-дискуссии. ошибка была моей, и я извинился за это. но все еще вниз. – makboney

ответ

2

Вы можете обращаться с этим в 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 
} 

Обратите внимание, что вам необходимо включить поддержку поддержки App Group, если вы хотите обмениваться контактами из приложения на любое расширение. Вот некоторые рекомендации:

  1. Apple Document
  2. Stack Overflow link