In the application it is every time i got on the pop-up message ask me for the user's password
That’s usually caused by an authentication failure, meaning you haven’t set up the user’s credentials properly. Make sure you:
This last part is a bit tricky. Pasted in below is the code I use for it.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
| import Foundation |
| |
| |
| |
| enum VPNKeychain { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static func persistentReferenceFor(service: String, account: String, password: Data) throws -> Data { |
| var copyResult: CFTypeRef? = nil |
| let err = SecItemCopyMatching([ |
| kSecClass: kSecClassGenericPassword, |
| kSecAttrService: service, |
| kSecAttrAccount: account, |
| kSecReturnPersistentRef: true, |
| kSecReturnData: true |
| ] as NSDictionary, ©Result) |
| switch err { |
| case errSecSuccess: |
| return try self.persistentReferenceByUpdating(copyResult: copyResult!, service: service, account: account, password: password) |
| case errSecItemNotFound: |
| return try self.persistentReferenceByAdding(service: service, account:account, password: password) |
| default: |
| try throwOSStatus(err) |
| |
| |
| fatalError() |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private static func persistentReferenceByUpdating(copyResult: CFTypeRef, service: String, account: String, password: Data) throws -> Data { |
| let copyResult = copyResult as! [String:Any] |
| let persistentRef = copyResult[kSecValuePersistentRef as String] as! NSData as Data |
| let currentPassword = copyResult[kSecValueData as String] as! NSData as Data |
| if password != currentPassword { |
| let err = SecItemUpdate([ |
| kSecClass: kSecClassGenericPassword, |
| kSecAttrService: service, |
| kSecAttrAccount: account, |
| ] as NSDictionary, [ |
| kSecValueData: password |
| ] as NSDictionary) |
| try throwOSStatus(err) |
| } |
| return persistentRef |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private static func persistentReferenceByAdding(service: String, account: String, password: Data) throws -> Data { |
| var addResult: CFTypeRef? = nil |
| let err = SecItemAdd([ |
| kSecClass: kSecClassGenericPassword, |
| kSecAttrService: service, |
| kSecAttrAccount: account, |
| kSecValueData: password, |
| kSecReturnPersistentRef: true, |
| ] as NSDictionary, &addResult) |
| try throwOSStatus(err) |
| return addResult! as! NSData as Data |
| } |
| |
| |
| |
| |
| |
| private static func throwOSStatus(_ err: OSStatus) throws { |
| guard err == errSecSuccess else { |
| throw NSError(domain: NSOSStatusErrorDomain, code: Int(err), userInfo: nil) |
| } |
| } |
| } |