iOS Dev Course: Biometrics Auth with LocalAuthentification on SwiftUI + Combine
Hello dear reader, so now we’ll create simple app that demonstrates how LocalAuthentification works to auth via Touch/Face ID and detect their changes.
What we need to start?
- Swift UI simple app project
- LocalAuthentification framework
Preparation
Create a new Single View App project.
Hotkey: shift + command + N
Setup as SwiftUI project
Create ViewModel class
It is class that conforms to protocol ObservableObject.
properties:
- loggedIn — indicates that LAContext evaluation result
- hasChanges — indicates changes between current and last LAContext domainStates
- domainState — saved LAContext evaluatedPolicyDomainState
functions:
- auth — evaluate LAContext to conform biometrics
- check — retrieve LAContext evaluatedPolicyDomainState and compare it value with saved domainState to detect changes
- checkDomainState — compare new and current domainState
Connect ViewModel into ContentView
Be sure that you modified ContentView_Previews and add environmentObject usage to that func
Modify SceneDelegate to pass ViewModel into ContentView
Run on simulator.
Yeah! Have tried biometric auth in action!
You’ve done it! Clap! Clap!
Remember, the receipt to success is continuous learning and communication with colleagues including, self-education.
This was a small guide about LocalAuthentification implemented in SwiftUI project via Combine — a part of iOS SDK that provides biometric authentification. Read more on Apple Developer site. Don’t stop self-education.
Subscribe to my account to get notifications about new stories.
If you still have questions — write about it in the comments. I’ll answer them in future articles.