Reputation: 7031
Is there anyway to see if the user activated notification center from the lock screen? I have some private information in a widget that I want to hide if the iPhone is still locked.
Upvotes: 2
Views: 1294
Reputation: 1194
It's a bit hacky, but here's the way I do it:
1) When your app first launches, create a dummy file in your shared container and set it's NSFileProtectionKey attribute to NSFileProtectionComplete. Let's call it ProtectionMonitor.dummy
2) When your widget launches, try to get data from the file. If it fails, the device is locked.
3) Monitor the UIApplicationProtectedDataDidBecomeAvailable and UIApplicationProtectedDataWillBecomeUnavailable notifications in your extension: it is possible for the user to unlock the device with touch ID whilst the Notification Centre is displayed. You could even suggest touch ID to your users to access private data from your widget when accessed from the lock screen.
Upvotes: 3