我使用意图整合Sirikit,Bill Payment:
INPayBillIntentHandling(最近于2017年3月27日在iOS 10。0 +上发布)。
Apple文档是here。
注意:我使用的是Swift语言,XCode 8.3,设备iPhone 6和iOS 10.3.3&演示项目iOS部署目标是iOS 10.3并且在第一次被问到许可时启用了Siri,并且还验证了In Settings,Siri已启用。 当我在设备上启动应用程序并使用DemoApp"说" Bill付款时,Siri说"你可以在DemoApp上获得这些信息,你想去DemoApp吗?"
请帮帮我。在此先感谢!
到目前为止,我执行了以下步骤:
1)创建一个演示Xcode项目
2)在主要应用程序功能中,启用Siri。
3)使用
添加Sirikit扩展名档案 - >新 - >添加目标 - >意图扩展 - >下一步 - >添加ProductName并说完
注意:我已禁用Sirikit UI扩展程序。 4)在主AppDelegate.swift中添加了以下内容:
import Intents
INPreferences.requestSiriAuthorization { (status) in
if status == INSiriAuthorizationStatus.authorized{
print("Authorized")
}else
{
print("Not authorized")
}
}
return true
5)在主应用程序Info.plist中,添加了带有使用说明的关键NSSiriUsageDescription
6)在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's question的问题相同,只是将其修改为swift,问题仍在等待答案,谢谢:)
答案 0 :(得分:1)
我不确定您是否已找到解决方案。对我来说有用的是在主项目10.3+中看到SiriExtension的部署目标为10.3+以及部署目标。同时将触发短语更改为“使用demoapp支付账单”。
Apple开发者论坛链接: https://forums.developer.apple.com/thread/71488
答案 1 :(得分:0)
尝试在测试手机中安装iOS 11 beta 5。
我正在试用iOS 11 beta 5使用swift并且更加稳定。