Siriと統合された支払いアプリケーションのセキュリティを強化しようとしています。 Appleのサンプルコードをlinkから使用し、支払いを実行する前にタッチID認証を実装するために以下を調整しました:
(タッチID認証の機能「認証」を追加し、ハンドル機能で呼び出しました)Sirikitによる支払いのセキュリティの向上
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()
}
問題はシリは言うです:慎重にデバッグした後
私はあなたと同じ問題に直面していると思うhttp://stackoverflow.com/questions/39686056/siri-intenthandler-not-behaving-correctly-with-device-touch-id –