요약
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())
}
}
는 말 :
혹시 다시이 값을 시리를 제공하면 내가 그 라인을 디버깅하고 볼을 제안 : 어떤이 라인에서 쿼리가 2 명 이상을 반환 유지 의미 주어진 이름을 사용하면 Siri가 반복적으로 연락처를 지정하도록 사용자에게 요청하는 루프를 보냅니다. "라는 말은 switch 문에서 case 0을 치는 것을 의미합니까? – rocky
@rocky 그렇지 않은 경우 1. 수신자가 일치했지만 Siri가 질문을 다시 한 번 인쇄합니다. – cyril
recipientMatched가 INPerson 유형입니까? – rocky