【问题标题】:Increasing security for payment with Sirikit使用 Sirikit 提高支付安全性
【发布时间】:2016-10-16 10:46:10
【问题描述】:

我正在尝试提高与 Siri 集成的支付应用的安全性。 我使用了来自 link 的 Apple 示例代码,并调整了以下内容以在执行支付之前实现触摸 ID 身份验证:
(新增touch ID认证的authenticate函数,并在handle函数中调用)

 func handle(sendPayment intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {
    self.authenticate(successAuth: {

        guard let payee = intent.payee,
            let payeeHandle = payee.personHandle,
            let currencyAmount = intent.currencyAmount,
            let amount = currencyAmount.amount,
            let currencyCode = currencyAmount.currencyCode
            else {
                completion(INSendPaymentIntentResponse(code: .failure, userActivity: nil))
                return
        }

        self.contactLookup.lookup(emailAddress: payeeHandle.value) { contact in
            guard let contact = contact else {
                completion(INSendPaymentIntentResponse(code: .failure, userActivity: nil))
                return
            }

            let payment = Payment(contact: contact, amount: amount, currencyCode: currencyCode)

            self.paymentProvider.send(payment) { success, _, _ in
                guard success else {
                    completion(INSendPaymentIntentResponse(code: .failure, userActivity: nil))
                    return
                }

                let response = INSendPaymentIntentResponse(code: .success, userActivity: nil)
                response.paymentRecord = self.makePaymentRecord(for: intent)

                completion(response)
            }
        }
        }) { (error) in
            print("error in authentication")
            completion(INSendPaymentIntentResponse(code: .failure, userActivity: nil))
            return
    }

}

func authenticate(successAuth: @escaping () -> Void, failure: @escaping (NSError?) -> Void) {
    // 1. Create a authentication context
    let authenticationContext = LAContext()
    var error:NSError?
    guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
        failure(error)
        return
    }
    // 3. Check the fingerprint
    authenticationContext.evaluatePolicy(
        .deviceOwnerAuthenticationWithBiometrics,
        localizedReason: "Unlock to send the money",
        reply: { [unowned self] (success, error) -> Void in

            if( success ) {
                successAuth()

            }else {
                let message = self.errorMessageForLAErrorCode(errorCode: (error! as NSError).code)
                print(message)
                failure(error! as NSError)
            }

        })
    successAuth()
}

问题是 Siri 说:“抱歉,你需要在应用程序中继续”

【问题讨论】:

标签: ios swift siri sirikit


【解决方案1】:

经过仔细调试,发现问题只有在Siri建议last payee或last currency amount时才会出现,于是我在resolvePayee和resolveCurrencyAmount中注释了这些部分,流程完美!确认付款后,要求进行 Touch ID 认证,然后发送付款。谢谢大家!

【讨论】:

  • “Siri 建议最后一个收款人或最后一个货币金额”是什么意思?
猜你喜欢
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2017-12-29
  • 2012-08-31
  • 2020-04-12
相关资源
最近更新 更多