gpt4 book ai didi

swift - 如何在 INSendPaymentIntent (SiriKit) 中搜索特定联系人?

转载 作者:搜寻专家 更新时间:2023-10-31 19:37:46 24 4
gpt4 key购买 nike

总结
尝试对 INSendPaymentIntent 进行编码,但无法区分具有相似名字的联系人。 Siri 似乎在 INPersonResolutionResult.disambiguation(with: matchedContacts)

之后进入循环

代码背后的想法
我最初选择使用联系人的名字来搜索联系人,因为如果用户仅指定名字,使用 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 会在您返回时要求确认此人的姓名:

completion(INPersonResolutionResult.needsValue())

或者这个:

completion(INPersonResolutionResult.disambiguation(with: matchedContacts))

在这种情况下,我认为它更有可能进入循环,因为您一直返回第二个结果 (INPersonResolutionResult.disambiguation)。这意味着您在这一行中的查询不断返回 2 个人或更多:

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

我建议您调试该行,看看您是否曾将此值返回给 Siri:

INPersonResolutionResult.success

关于swift - 如何在 INSendPaymentIntent (SiriKit) 中搜索特定联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38767968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com