摘要
试图编码INSendPaymentIntent
,但在区分具有相似名字的联系人时遇到问题。 Siri的似乎走在一个循环之后INPersonResolutionResult.disambiguation(with: matchedContacts)
如何搜索INSendPaymentIntent(SiriKit)中的特定联系人?
思考
我选择最初使用联系人的给定的名称来搜索联系人,因为使用INPerson
显示名称后面的代码返回的查询,如果匹配的第一个接触用户只能指定名字。 (即'支付凯文$ 50'将自动选择凯文派西凯文斯派西)。
不幸的是,利用给定的名称发送的Siri成一个圈,询问用户一遍又一遍的指定联系人......
问题
是否有使用通过搜索联系人的联系人首个什么办法名称没有发送Siri成循环?
代码
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())
}
}
当你说“使用给定的名称将Siri发送到一个循环中,要求用户反复指定联系人“,这是否意味着您正在切换语句的情况0? – rocky
@rocky nope它的情况1.日志打印,收件人匹配,但Siri再次提出问题。 – cyril
您确定recipientMatched是INPerson类型吗? – rocky