قالب وردپرس درنا توس
Home / IOS Development / ios – Customize actions for keychain alerts

ios – Customize actions for keychain alerts



I wonder if customizing the keychain alert is possible? Below you can find the image:

  enter image description here

What I am trying to achieve:

When the authentication with FaceID / TouchID fails and shows up over the displayed notification, I want the user to press Enter password and show my custom application password code user interface, instead of device password (system ui). Basically, I want to customize the fallback action.

Context:
I know it is possible to use LAContext but because of the reasons we can work around it, I don't feel comfortable implementing it, so I chose Keychain accessControlFlags.

Snapshot code, what I currently have:

  func data (for account account: String, service: String, accessGroup: String?) Throws -> Data? {
guard let accessControl = createAccessControl (with: .userPresence) else {return nil}
var query = self.query (forAccount: account, service: service, accessGroup: accessGroup)

var autorContext = LAContext ()
authContext.localizedFallbackTitle = "Set password"
autorContext.localizedCancelTitle = "Cancel"

query [KeychainConstants.matchLimit] = KeychainConstants.matchLimitOne
query [KeychainConstants.returnData] = kCFBooleanTrue
query [KeychainConstants.authenticationContext] = authContext
query [KeychainConstants.accessControl] = accessControl

was the result: AnyObject?
let status = withUnsafeMutablePointer (to: & result) {
securityItemManager.copyMatching (query, result: UnsafeMutablePointer ($ 0))
}

if let error = error (fromStatus: status), error! = .itemNotFound {
throws error
}
guard result! = null else {return nil}
guard let resultData = result that? Else data {throw AccessError.invalidQueryResult}
return result data
}


Source link