Reputation: 2401
I have a widget that displays some sensitive data. We know that the iOS widgets can be placed both on the home screen and the Today widget page.
Today widget page
page can be visible even from the locked state! Here is the problem that arises, I want to hide the content if the user locked their mobile.
I can see this behavior has done in the iOS Screen Time
widget. If we locked the mobile no data is exposed. Once if I unlock (AKA activate the Face ID), All the data is visible.
Upvotes: 3
Views: 1545
Reputation: 29309
You do it by enabling Data Protection Capability
https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension
You need to set the Data Protection Entitlement
NSFileProtectionComplete or NSFileProtectionCompleteUnlessOpen, and the device is locked.
In Swift 5.5 iOS 15+ there is a new ViewModifier
.privacySensitive(true)
Just add it to the View
that has the sensitive content
https://developer.apple.com/videos/play/wwdc2021/10018/
Upvotes: 4