- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
总结
尝试对 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/
上下文 我正在努力为一个重要的应用程序添加对 Siri 快捷方式(Intents?)的支持。我的主要目标是允许用户使用 Shortcuts.app 自动执行应用程序中的某些任务。 我在 Intents
我目前正在我的应用程序中添加 SiriKit,并且我已经创建了一个 INExtension 类。在我的 Info.plist 中,我有以下代码。 但是每次我尝试在设备上运行 Intent Extens
我正在尝试弄清楚如何使用 iOS12 中的自定义意图来定义和创建快捷方式。我想创建一个快捷方式,以便用户可以将任务添加到我的应用程序并为其命名(以及将来的其他参数)。例如只需对 Siri 说“添加名称
我刚刚创建了单 View Controller 应用程序并添加了带有 Siri 扩展(intents 和 intent ui 扩展)的目标。但是当我说 Siri 命令启动意图时,它只是启动应用程序而不
我将 SiriKit 添加到我的一个版本中,但后来决定将其删除。问题是,当我要求 Siri 执行该应用程序过去执行的功能时,Siri 仍然愿意使用我的应用程序。我已经删除并重新安装了该应用程序(不支持
我想了很多关于 Siri 如何改进我的应用程序的用户体验。 我正在编写一个专用于健身的应用程序,用于记录您的锻炼和个人记录。 我想让用户使用 Siri 来使用我的应用程序的功能,但我真的不明白这是否可
我有一个应用程序,用户可以在其中订购咖啡。我阅读了以下有关 SiriKit 支持的基本域的文章 - https://developer.apple.com/documentation/sirikit
我发出的任何通过 Siri 向联系人汇款的请求都会触发网络搜索,将语音输入传递给 Safari(即“向 Bob 汇款 100 美元”)。 我已在我的应用功能中启用 Siri,并将 INSendPaym
我在 Xcode 的 Capabilities 中启用了 Siri,我还将 NSSiriUsageDescription 添加到我的父应用程序 plist 文件中,并在我的第一个 Controller
我在 wwdc 上观看了 SiriKit 并阅读了文档。 https://developer.apple.com/library/prerelease/content/documentation/In
我构建了 Intents Extension,我正在处理 INSendMoneyIntent,我说: Send 25€ to John Smith 应用确认后的响应 Here's your paym
我有一个道路救援服务应用程序。它具有一些类似于乘车预订应用程序(例如优步)的功能。我可以在多大程度上利用 iOS 10 Sirikit?可能是,苹果可以拒绝它。但我需要知道技术可行性。 我的应用程序的
IntentHandler类: import Intents class IntentHandler: INExtension, INStartWorkoutIntentHandling {
我想在我的一个应用程序中实现录音功能。可以使用sirikit吗?我目前没有找到任何通过 sirikit 录音的教程。 有人可以提供关于sirikit的好的教程吗? 最佳答案 正确地知道您不能通过以下方
我正在将SiriKit集成到我的iOS 13应用程序中。 为此,我使用Apple's Sample app - Soup Chef来理解它。 在我的自定义意图中,我在快捷方式应用程序中选择了Ask E
我有一个问题,Siri 总是用我的意图的英文版本来回应。我创建了一个演示项目来分离出相关代码: 我的项目中有 3 个目标: .intentsdefinition文件位于框架 (Base) 中,并且类也
我一直在开发一个应用程序,尝试实现 requestPaymentIntent。它首先可以工作,但在某个时候它开始进行 Bing 搜索,并且在某个时候只是说它发现了一个错误,之后什么也不做。主题中也指出
我正在尝试实现一个航空公司应用程序,它将以文本方式对讲并为用户返回里程。我正在使用 INSearchForAccountsIntentHandling 协议(protocol)来实现它。 就像我希望
我正在使用测试应用程序和扩展来尝试 SiriKit 驱魔。我的分机根本没有被调用,我不知道为什么。我在另一个应用程序中有一个工作的 SiriKit 扩展程序,它莫名其妙地停止响应 - 因此这个测试应用
在我第一次构建并运行我的 intents 项目后,从 Siri 请求某些东西总是返回抱歉,您需要在应用程序中继续 但是,在我重建之前,它每次都有效。 我在处理程序中放置了断点: override fu
我是一名优秀的程序员,十分优秀!