我正在努力提高与Siri集成的付款应用的安全性。
我使用了此link中的Apple示例代码,并在执行付款之前调整了以下内容以实现触摸ID身份验证:
(添加功能"验证"用于触摸ID验证,并在句柄功能中调用它)
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说:"抱歉,您需要继续使用应用程序"
答案 0 :(得分:3)
经过仔细的调试后,我发现只有当Siri建议最后一个收款人或最后一个货币金额时才会出现问题,所以我在resolvePayee和resolveCurrencyAmount中对这些部分进行了评论,并且流程运行良好!确认付款后,它会要求进行触摸身份验证,然后发送付款。谢谢你们!