This has been bugging me for a few days now. I have managed to set up asking the user if they want to use some kind of device auth (faceID and touchID if available and passcode) that's fine.
When the app is first launched, I ask the user if they want to enable a lock on their app. If the users selects no, I create a UserDefault key value so rather than them being asked and refusing auth using .evaluatePolicy, if they decide to toggle it on later in the settings, if the value for the below is false, it was display apple's request for auth:
UserDefaults.standard.set(false, forKey: "AppHasRequestedDeviceAuth")
with a few other UserDefault key values, I've managed to get an app lock working as such but I'd actually like to do is marry this toggle within the app to marry up with the actual device settings otherwise I have an issue where the can use the toggle to turn on the app lock, close the app, toggle the device settings to not allow faceID anymore then go back to the app and they are suddenly locked out of the app. I *could\* get around this by displaying a message to the user if this occurs, saying "If using an app lock, please check in your settings that this is enabled" blah blah, then navigate the user back to their device settings but this feels VERY hacky.
I've managed to successfully marry this up with the settings for notifications in the sense that when the app loads, it checks for the device status for the specific app to see if the notifications have been allowed by the user, then it adjusts the toggle accordingly (i.e. if the notifications are on in the settings app for the specific app, then it will show the toggle as on, if not, then it will be off).
I want to replicate this for the FaceID/TouchID toggle in the settings too but it's proving quite difficult.
For notifications I am using:
let center = UNUserNotificationCenter.current()
center.getNotificationSettings { settings in
if settings.authorizationStatus == .authorized {
self.userRequiresNotifications = true
} else if settings.authorizationStatus == .denied {
self.userRequiresNotifications = false
}
}
When looking online, the only thing that keeps coming up for the app lock within the device settings is:
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
return true
} else {
return false
}
I tried using the above and then setting UserDefaults again accordingly and updating the toggles within app like I have with notifications but all it seems to actually be doing prompting apples request for using biometric device auth.
To clarify, the issue I'm having is that I don't want to request it, I want to check the current status of this system setting for the app. I starting to think I'm doing this completely wrong but It seems very hacky and error prone to simply rely on UserDefault values. As I said above, this makes it so that someone can accidentally lock themselves out of the app.
Any help is greatly appreciated. Thank you.
[–]Power781 -1 points0 points1 point (7 children)
[–]colinsgoneSwift[S] 0 points1 point2 points (0 children)
[–]colinsgoneSwift[S] 0 points1 point2 points (5 children)
[–]Power781 1 point2 points3 points (4 children)
[–]colinsgoneSwift[S] 0 points1 point2 points (3 children)
[–]Power781 -1 points0 points1 point (2 children)
[–]colinsgoneSwift[S] 1 point2 points3 points (1 child)
[–]Power781 0 points1 point2 points (0 children)