inf*_*eqd 4 security touch-id sirikit
尝试了解以下内容:
https://developer.apple.com/videos/play/wwdc2016/225/ 提到sendPayments意图默认是IntentsRestrictedWhileLocked,但是如果我们想提高安全性以便用户需要使用Touch Id(本地身份验证)进行批准,那么这该怎么办呢?当设备锁定/解锁时都需要这样做。我假设扩展程序需要在“确认”阶段以某种方式显示本地身份验证 UI?
他们还提到可以提高安全性,但只需要确认执行此操作的机制是否只是 IntentsRestrictedWhileLocked 扩展属性?或者有没有办法指定需要touch id身份验证?
小智 5
为了回答这两个问题,是的,您可以通过 Touch ID 提高支付的安全性,这是我在 Apple 的示例代码中实现的方法,我在 SendPaymentIntentHandler.swift 中添加了以下函数:
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)
}
})
}
func errorMessageForLAErrorCode( errorCode:Int ) -> String{
var message = ""
switch errorCode {
case LAError.appCancel.rawValue:
message = "Authentication was cancelled by application"
case LAError.authenticationFailed.rawValue:
message = "The user failed to provide valid credentials"
case LAError.invalidContext.rawValue:
message = "The context is invalid"
case LAError.passcodeNotSet.rawValue:
message = "Passcode is not set on the device"
case LAError.systemCancel.rawValue:
message = "Authentication was cancelled by the system"
case LAError.touchIDLockout.rawValue:
message = "Too many failed attempts."
case LAError.touchIDNotAvailable.rawValue:
message = "TouchID is not available on the device"
case LAError.userCancel.rawValue:
message = "The user did cancel"
case LAError.userFallback.rawValue:
message = "The user chose to use the fallback"
default:
message = "Did not find error code on LAError object"
}
return message
}
Run Code Online (Sandbox Code Playgroud)
然后在handle方法中调用函数authenticate,结果是我的应用程序在确认付款后要求进行Touch ID身份验证,然后在用户验证自己身份后成功发送付款。
| 归档时间: |
|
| 查看次数: |
1006 次 |
| 最近记录: |