Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save treastrain/3ff2408db10ce434c289095bb8b81a6c to your computer and use it in GitHub Desktop.
Save treastrain/3ff2408db10ce434c289095bb8b81a6c to your computer and use it in GitHub Desktop.
macOS Command Line Tool で Local Authentication を使って MacBook Pro の Touch ID で認証する Swift プログラム
//
// AuthenticationByTouchIDWithMacOSCommandLineTool.swift
//
//
// Created by treastrain on 2021/03/26.
//
import LocalAuthentication
let context = LAContext()
var error: NSError?
let policy = LAPolicy.deviceOwnerAuthenticationWithBiometricsOrWatch
guard context.canEvaluatePolicy(policy, error: &error) else {
fatalError(error!.localizedDescription)
}
switch context.biometryType {
case .none:
print("No biometry type is supported.")
case .touchID:
print("The device supports Touch ID.")
case .faceID:
print("The device supports Face ID.")
@unknown default:
print("The device supports unknown biometry type.")
}
if let error = error {
print("Error:", error)
exit(EXIT_FAILURE)
}
let reason = "Touch ID で解除"
context.evaluatePolicy(policy, localizedReason: reason) { (success, error) in
print("success:", success, "error:", error)
exit(EXIT_SUCCESS)
}
RunLoop.current.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment