2017-01-04 44 views
-26

我正在實施一個VoIP應用程序,我需要通過Siri發起呼叫。我能夠通過Siri發起呼叫。但問題是 - 每次應用程序啓動時,雖然聯繫人不在應用程序的聯繫人列表中。Siri - 聯繫人搜索行爲類似於Skype的音頻呼叫

我不知道如何以及在哪裏處理。我的意思是如果應用程序沒有像Skype那樣的聯繫人處理它,則不會啓動該應用程序。 Skype回覆如下:

嗯,Skype沒有找到<用戶>。

您想給誰打電話?

貝婁是我的擴展處理程序的代碼片段:

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

討論[上元(http://meta.stackoverflow.com/questions/340839/user-answers-a-question-of -another用戶和 - 詢問最相同問題-再次-已經?CB = 1)。我認爲我們可以停止downvoting。 –

+0

@ThomasWeller感謝您的回覆。我試圖在meta討論中說清楚。錯誤是我的,我爲此道歉。但仍然下調。 – 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 
} 

請注意,如果您想要將應用程序中的聯繫人共享到任何擴展程序,您可能需要啓用應用程序組支持。下面是一些指導原則:

  1. Apple Document
  2. Stack Overflow link
相關問題