ios - Siri - Lang Swift 3,INPayBillIntent 不工作,Siri 说 "You will have to continue in DemoApp, Would you like to open it?"

标签 ios iphone swift xcode siri

我正在集成 Sirikit,Bill Payment,目的是:

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

Apple 文档是 here .

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

请帮帮我。提前致谢!

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

1) 创建一个 Demo Xcode 工程

2) 在 Main App Capabilities 中,启用 Siri。

3) 使用添加的 Sirikit 扩展

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

注意:我已经禁用了 Sirikit UI 扩展。 4) 在 Main AppDelegate.swift 添加了以下内容:

import Intents

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

5) 在 Main app Info.plist 中,添加带有使用说明的键 NSSiriUsageDescription

6) IntentExtension, Info.plist, NSExtension->IntentsSupported->added key INPayBillIntent

7) 在 IntentHandler.swift 中,添加:

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

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

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 修改了它,问题还在等待答案,谢谢 :)

最佳答案

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

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

关于ios - Siri - Lang Swift 3,INPayBillIntent 不工作,Siri 说 "You will have to continue in DemoApp, Would you like to open it?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45541947/

相关文章:

ios - MVVMCross + SQLCipher = 不可能?

iphone - 应用程序在 iPhone 上崩溃但在模拟器或 iPad 上不崩溃?

ios - 如果一个节点被缩放,包含的 scntext 边界框不是太正常,这是否正常?

swift - 指定非时,编译器坚持要求外部参数标签

ios - 如何使用 Swift 模糊 UIImageView 中的现有图像?

ios - 使用 STTwitterAPI 使用 twitter 登录一次

ios - 模块 HMRClient 不是注册的可调用模块 (iOS)

ios - UITableView 需要长按选择一行

ios - 无法在 iPad (Swift iOS) 中运行应用程序

ios - 用户输入的值保存到核心数据(?)但未出现在 TableView 中