Siri - Lang Swift 3,INPayBillIntent不起作用,Siri说"You will have to continue in DemoApp, Would you like t



我正在整合Sirikit,账单支付的意图是:

INPayBillIntentHandling(最近在iOS 10.3+中发布,2017年3月27日(。

苹果文档在这里。

注意:我使用的是Swift语言,XCode 8.3,带有iOS 10.3.3的设备iPhone 6和演示项目iOS部署目标是iOS 10.3,并且在第一次询问权限时还启用了Siri,并验证了在设置中启用了Siri。 当我在设备上启动应用程序并说"使用DemoApp支付账单"时,Siri说"您可以在DemoApp上获取此信息,您想去DemoApp吗?

请帮助我。提前感谢!

到目前为止,我执行了以下步骤:

1( 创建一个演示 Xcode 项目

2(在主应用程序功能中,启用了Siri。

3( 添加了诗丽吉扩展程序使用

文件 -> 新建 -> 添加目标 ->意图扩展 -> 下一步 ->添加产品名称并说完成

注意:我已禁用 Sirikit UI 扩展。 4( 在主应用程序代表中.swift添加了以下内容:

import Intents
INPreferences.requestSiriAuthorization { (status) in
if status == INSiriAuthorizationStatus.authorized{
print("Authorized")
}else
{
print("Not authorized")
}
}
return true

5(在主应用程序Info.plist中,添加了带有使用描述的密钥NSSiriUsage描述

6( In IntentExtension, Info.plist, NSExtension->IntentsSupported->添加了键 INPayBillIntent

7(在IntentHandler.swift中,添加了以下内容:

override func handler(for intent: INIntent) -> Any {
if intent is INPayBillIntent{
print("Response: payBill")
return PayBillHandler()
}

8( 在 PayBillHandler 中.swift添加了 INPayBillIntentHandling 的所有委托方法:

import Intents

class PayBillHandler: NSObject, INPayBillIntentHandling {
func handle(intent: INPayBillIntent, completion: @escaping (INPayBillIntentResponse) -> Void){
let userActivity = NSUserActivity(activityType: NSStringFromClass(INPayBillIntent.self))
let response = INPayBillIntentResponse(code: .ready, userActivity: userActivity)
completion(response)
}
func resolveBillType(for intent: INPayBillIntent, with completion: @escaping (INBillTypeResolutionResult) -> Void) {
let finalResult = INBillTypeResolutionResult.success(with: .water)
completion(finalResult)
}
func resolveBillPayee(for intent: INPayBillIntent, with completion: @escaping (INBillPayeeResolutionResult) -> Void) {
let speakableStr = INSpeakableString(identifier: "XXX", spokenPhrase: "XXX", pronunciationHint: "XXX")
let speakableStr1 = INSpeakableString(identifier: "YYY", spokenPhrase: "YYY", pronunciationHint: "YYY")
let billPayee = INBillPayee(nickname: speakableStr, number: "10112122112", organizationName: speakableStr1)
let finalResult = INBillPayeeResolutionResult.success(with: billPayee!)
completion(finalResult)
}
func resolveTransactionNote(for intent: INPayBillIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
let finalResult = INStringResolutionResult.success(with: "Bill Payment")
completion(finalResult)
}
func resolveDueDate(for intent: INPayBillIntent, with completion: @escaping (INDateComponentsRangeResolutionResult) -> Void) {
completion(INDateComponentsRangeResolutionResult.notRequired())
}
func resolveFromAccount(for intent: INPayBillIntent, with completion: @escaping (INPaymentAccountResolutionResult) -> Void) {
let speakableStr2 = INSpeakableString(identifier: "Someone", spokenPhrase: "Someone", pronunciationHint: "Someone")
let speakableStr3 = INSpeakableString(identifier: "", spokenPhrase: "", pronunciationHint: "organisation")
let fromAccount = INPaymentAccount(nickname: speakableStr2, number: "10112122112", accountType: .credit, organizationName: speakableStr3)
let finalResult = INPaymentAccountResolutionResult.success(with: fromAccount!)
completion(finalResult)
}
func resolveTransactionAmount(for intent: INPayBillIntent, with completion: @escaping (INPaymentAmountResolutionResult) -> Void) {
let currencyAmmount = INCurrencyAmount(amount: NSDecimalNumber(string: "100"), currencyCode: "USD")
let transactionAmt = INPaymentAmount(amountType: .amountDue, amount: currencyAmmount)
let finalResult = INPaymentAmountResolutionResult.success(with: transactionAmt)
completion(finalResult)
}
func resolveTransactionScheduledDate(for intent: INPayBillIntent, with completion: @escaping (INDateComponentsRangeResolutionResult) -> Void) {
completion(INDateComponentsRangeResolutionResult.notRequired())
}
func confirm(intent: INPayBillIntent, completion: @escaping (INPayBillIntentResponse) -> Void) {
let response = INPayBillIntentResponse(code: .success, userActivity: nil)
completion(response)
}
}

顺便说一下,这与Joao Nunes的问题相同,只是为了快速修改了它,问题仍在等待答案,谢谢:)

我不确定您是否已经找到了解决方案。对我有用的是看到SiriExtension的部署目标是10.3+以及主项目10.3+中的部署目标。还将触发短语更改为"使用 demoapp 支付账单"。

Apple 开发者论坛链接: https://forums.developer.apple.com/thread/71488

尝试将iOS 11 beta 5安装到测试手机中。

我正在使用 swift 在 iOS 11 beta 5 上试用,并且更加稳定。

最新更新