当安装了多个帐单支付应用程序时,INPayBillIntentHandling不会调用所需的协议方法

时间:2017-08-22 08:43:26

标签: ios swift sirikit

我正在尝试通过Siri实施账单支付延期。在扩展程序用户只指定帐单类型,输入后,他/她将被定向到应用程序并需要登录。如果只有支持账单支付的应用程序安装在设备中,一切正常。甚至支持通过Siri发送资金的应用程序也可能导致不必要的行为该问题的另一个发现是,如果设备OS版本在10.3和11之间,则会遇到此问题。但是,在iOS 11 v6中,这个问题似乎已得到解决。

问题:几乎总是Siri不会输入方法handle(intent:completion:),这是必需的INPayBillIntentHandling协议方法。扩展仅询问帐单类型,输入解析协议方法并输入可选协议方法confirm(intent:completion:)。最后它需要输入handle方法但不输入方法。通过Siri打开主应用程序后,AppDelegate的application:continueUserActivity:restorationHandler:方法也没有调用。

编辑:我还有另一个正常运行的Siri扩展程序(发送付款)。

代码如下:

@available(iOSApplicationExtension 10.3, *)
class PayBillIntentHandler: NSObject, INPayBillIntentHandling {

public func handle(payBill intent: INPayBillIntent, completion: @escaping (INPayBillIntentResponse) -> Void) {
    completion(INPayBillIntentResponse(
        code: .inProgress,
        userActivity: process(intent: intent)))
    }

func confirm(payBill intent: INPayBillIntent, completion: @escaping (INPayBillIntentResponse) -> Void) {
    let userActivity = process(intent: intent)
    let success = (userActivity != nil)
    let code: INPayBillIntentResponseCode = success ? .success : .failureInsufficientFunds
        let response = INPayBillIntentResponse(code: code, userActivity: userActivity)
        response.billDetails = INBillDetails(billType: intent.billType,
                                             paymentStatus: .unpaid,
                                             billPayee: nil,
                                             amountDue: nil,
                                             minimumDue: nil,
                                             lateFee: nil,
                                             dueDate: nil,
                                             paymentDate: nil)

    completion(response)
    }

func resolveBillType(forPayBill intent: INPayBillIntent,
                     with completion: @escaping (INBillTypeResolutionResult) -> Void) {

       if intent.billType != .unknown {
           completion(INBillTypeResolutionResult.success(with: intent.billType))
       } else {
           completion(INBillTypeResolutionResult.needsValue())
       }
    }

@discardableResult fileprivate func process(intent: INPayBillIntent) -> NSUserActivity? {

        let userActivity = NSUserActivity(activityType: String(describing: INPayBillIntent.self))
        var properties = [String: Any]()

        properties["billType"] = billType: intent.billType.rawValue
        userActivity.userInfo = ["properties": properties]
    }
}

0 个答案:

没有答案