Created
March 26, 2021 09:59
-
-
Save treastrain/3ff2408db10ce434c289095bb8b81a6c to your computer and use it in GitHub Desktop.
macOS Command Line Tool で Local Authentication を使って MacBook Pro の Touch ID で認証する Swift プログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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