2016-08-04 2 views
4

요약
INSendPaymentIntent을 코딩하려고하지만 비슷한 이름을 가진 연락처를 구별하는 데 어려움이 있습니다. 시리 바로 내가 INPerson 표시 이름을 사용하기 때문에 처음에 연락처를 검색 할 연락처의 지정된 이름을 사용하기로 결정했습니다
강령 뒤에 INPersonResolutionResult.disambiguation(with: matchedContacts)INSendPaymentIntent (SiriKit)에서 특정 연락처를 검색하려면 어떻게해야합니까?

생각 후 루프에 갈 것 같다 경우 쿼리 일치하는 첫 번째 접촉을 반환 사용자는 이름 만 지정합니다. (즉, 'Pay Kevin $ 50'은 Kevin Spacey보다 Kevin Bacon을 자동으로 선택합니다)

불행하게도, 지정된 이름을 사용하면 연락처의 사용하여 연락처를 검색하는 방법은 없나요 ... 또 다시

질문
을 연락처를 지정하도록 사용자에게 요구하는 루프에 시리를 전송 시리를 루프에 보내지 않고 이름을 지어야합니까?

코드

func resolvePayee(forSendPayment intent: INSendPaymentIntent, with completion: (INPersonResolutionResult) -> Void) { 
    if let payee = intent.payee { 
     var resolutionResult: INPersonResolutionResult? 
     var matchedContacts: [INPerson] = [] 
     let predicate = CNContact.predicateForContacts(matchingName: (payee.nameComponents?.givenName)!) 

     do { 
      let searchContactsResult = try CNContactStore().unifiedContacts(matching: predicate, keysToFetch:[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactMiddleNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactIdentifierKey]) 
      for contact in searchContactsResult { 
       matchedContacts.append(createContact((contact.phoneNumbers.first?.value.stringValue)!, contact: contact)) 
      } 
     } catch { 
      completion(INPersonResolutionResult.unsupported()) 
     } 

     switch matchedContacts.count { 
      case 2 ... Int.max: 
       resolutionResult = INPersonResolutionResult.disambiguation(with: matchedContacts) 
      case 1: 
       let recipientMatched = matchedContacts[0] 
       print("Matched a recipient: \(recipientMatched.displayName)") 
       resolutionResult = INPersonResolutionResult.success(with: recipientMatched) 
      case 0: 
       print("This is unsupported") 
       resolutionResult = INPersonResolutionResult.unsupported() 
      default: 
       break 
     } 

     completion(resolutionResult!) 
    } else { 
     completion(INPersonResolutionResult.needsValue()) 
    } 
} 
+0

는 말 :

let searchContactsResult = try CNContactStore().unifiedContacts(matching: predicate, keysToFetch:[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactMiddleNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactIdentifierKey]) 

혹시 다시이 값을 시리를 제공하면 내가 그 라인을 디버깅하고 볼을 제안 : 어떤이 라인에서 쿼리가 2 명 이상을 반환 유지 의미 주어진 이름을 사용하면 Siri가 반복적으로 연락처를 지정하도록 사용자에게 요청하는 루프를 보냅니다. "라는 말은 switch 문에서 case 0을 치는 것을 의미합니까? – rocky

+0

@rocky 그렇지 않은 경우 1. 수신자가 일치했지만 Siri가 질문을 다시 한 번 인쇄합니다. – cyril

+0

recipientMatched가 INPerson 유형입니까? – rocky

답변

1

당신이 반환 할 때마다 시리는 사람의 이름을 확인하기 위해 묻습니다이 :이 경우

completion(INPersonResolutionResult.disambiguation(with: matchedContacts)) 

:

completion(INPersonResolutionResult.needsValue()) 

또는이 , 나는 그것이 가능성이 더 높다고 생각합니다. 왜냐하면 두 번째 결과 (INPersonResolutionResult.disambiguation)를 계속 반환했기 때문입니다. "

INPersonResolutionResult.success 
관련 문제