I am developing an iOS app in SwiftUI that will need to lock/unlock cryptographic keys from the keychain before any operations can be performed. I would like to have those keys in memory while the app is in use, and then removed from memory when the user switches to another app or it goes into the background. When the app is launched or brought back into the foreground, I would like to prompt them for a password to unlock the keys.
I've done something like this in the past when using UIKit, but this app is being written in SwiftUI. The root of my app is a TabView
, with numerous other View
s displayed in each of the tabs. I would like this "lock screen" to pop up regardless of which View
happens to be active at the time. I know that there are numerous Notification
s that I can subscribe to in a UIApplicationDelegate. That can handle the task of removing the keys out of memory. What I don't know is how to display the lock screen View
over top of any other View
that may be active at the time.
Is there a "standard" SwiftUI way of accomplishing this? I'd like to adhere to SwiftUI best practices as much as possible, but haven't seen any good examples of how to do something like this.