2

(Related to this (a bit outdated) question, but not the same.)

Background

Xcode 7.2, iOS 9.2. I am updating some local authentication/keychain demo projects I did back then, to Swift 2.

I put the code below together and tested it on the simulator:

override func viewDidAppear(animated: Bool)
{
    super.viewDidAppear(animated)
    
    var error: NSError?

    let context = LAContext()
    
    
    guard context.canEvaluatePolicy(.DeviceOwnerAuthentication, error: &error) else {
        print("Can not evaluate policy")
        return
    }
    
    context.evaluatePolicy(.DeviceOwnerAuthentication,
        localizedReason: "Authenticate!",
        reply: { (success, error) -> Void in
            
            if success {
                print("SUCCESS")
            }
            else{
                switch LAError(rawValue: error!.code)! {
                case .AuthenticationFailed:
                    break
                case .UserCancel:
                    break
                case .UserFallback:
                    break
                case .SystemCancel:
                    break
                case .PasscodeNotSet:
                    break
                case .TouchIDNotEnrolled:
                    break
                default:
                    break
                }
            }
        }
    )
}

To my surprise, when I run this code on the "iPhone 5" or "iPhone 5s" simulators, the "Alphanumeric passcode" screen appears:

enter image description here

(there is no "Touch ID & Passcode" section in Settings.app for the simulator. Also, "Touch ID Enrolled" is unchecked in the Simulator's OSX menu)

If I tap the Cancel button (i.e., the "return" button while the password field is empty), authentication fails as expected (execution jumps to case .UserCancel: in the code above).

But if I type anything, the Cancel button will change to Done, and tapping it will cause authentication to succeed.

(If I enable Hardware > Touch ID Enrolled, the Simulate Finger Touch > works as expected.)

Questions:

  • Is there a way (that I'm missing) to set a specific passcode, and check against that? (instead of "anything passes validation")
  • Is there a way to choose 4-digit passcode, 6-digit passcode, etc. instead of the complex password format I'm seeing now?
Community
  • 1
  • 1
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189

0 Answers0