-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding unlockWithBiometrics and CI-tests.yml
- Loading branch information
Showing
9 changed files
with
168 additions
and
28 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: CI-tests | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
run-unit-tests: | ||
name: Run Unit Tests | ||
runs-on: macos-13 | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v3 | ||
- name: List Xcode Versions 📋 | ||
run: ls /Applications | grep Xcode | ||
- name: Select Xcode ✨ | ||
run: sudo xcode-select -switch /Applications/Xcode_15.0.1.app/Contents/Developer | ||
- name: List SDKs 🎊 | ||
run: xcodebuild -showsdks | ||
- name: Run tests (UI & Unit tests) ✅ | ||
run: xcodebuild -scheme ScribbleLab -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPad Pro (12.9-inch)' test |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Security.swift | ||
// ScribbleLab | ||
// | ||
// Created by Nevio Hirani on 16.12.23. | ||
// | ||
|
||
import Foundation | ||
import LocalAuthentication | ||
|
||
/// Typealias for biometric authentication completion handler | ||
typealias BiometricUnlockCompletion = (Bool, Error?) -> Void | ||
|
||
/// Performs biometric authentication using Face ID/Touch ID. | ||
/// | ||
/// - Parameters: | ||
/// - completion: A closure indicating the result of the authentication. | ||
/// The closure has two parameters: | ||
/// - success: A Boolean value indicating whether the authentication was successful. | ||
/// - error: An optional `Error` object containing details in case of failure. | ||
/// | ||
/// ## Example Usage: | ||
/// ```swift | ||
/// // Calling unlockWithBiometrics | ||
/// unlockWithBiometrics { success, error in | ||
/// if success { | ||
/// // Biometric authentication succeeded | ||
/// // Perform actions after successful authentication | ||
/// } else if let error = error { | ||
/// // Handle authentication error | ||
/// } else { | ||
/// // Handle generic authentication failure | ||
/// } | ||
/// } | ||
/// ``` | ||
func unlockWithBiometrics(completion: @escaping BiometricUnlockCompletion) { | ||
let context = LAContext() | ||
var error: NSError? | ||
|
||
// Check whether biometric authentication is possible | ||
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) { | ||
let reason = "Unlock with Face ID/Touch ID to open ScribbleLab" | ||
|
||
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in | ||
DispatchQueue.main.async { | ||
if success { | ||
completion(true, nil) | ||
} else if let error = authenticationError { | ||
completion(false, error) | ||
} else { | ||
completion(false, NSError(domain: "ScribbleLab", code: -1, userInfo: [NSLocalizedDescriptionKey: "Biometric authentication failed."])) | ||
} | ||
} | ||
} | ||
} else { | ||
// Biometrics not enabled or available | ||
completion(false, error) | ||
} | ||
} |