Azhagusundaram Tamil
Azhagusundaram Tamil

Reputation: 2401

How to Hide iOS 14 Widget Content when iPhone is locked?

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.

Locked State

Locked State

Unlocked State

Unlocked State

Upvotes: 3

Views: 1545

Answers (1)

lorem ipsum
lorem ipsum

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.

https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_default-data-protection

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

Related Questions