Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static func loadPassProtected(key: String, context: LAContext? = nil) -> Data? {
- var query: [String: Any] = [
- kSecClass as String : kSecClassGenericPassword,
- kSecAttrAccount as String : key,
- kSecReturnData as String : kCFBooleanTrue,
- kSecAttrAccessControl as String: getPwSecAccessControl(),
- kSecMatchLimit as String : kSecMatchLimitOne]
- if let context = context {
- query[kSecUseAuthenticationContext as String] = context
- // Prevent system UI from automatically requesting password
- // if the password inside supplied context is wrong
- query[kSecUseAuthenticationUI as String] = kSecUseAuthenticationUIFail
- }
- var dataTypeRef: AnyObject? = nil
- let status = SecItemCopyMatching(query as CFDictionary, &dataTypeRef)
- if status == noErr {
- return (dataTypeRef! as! Data)
- } else {
- return nil
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement