isProtectedDataAvailable is returning true always in iOS
Asked Answered
P

0

15

Problem

isProtectedDataAvailable is true but applicationProtectedDataDidBecomeAvailable is getting called after 10~20 seconds in iOS which means isProtectedDataAvailable was supposed to be false before that callback is called.


I am working on iOS app built in Objective C. I have enabled data protection (currently configured for FirstUserAuthentication) for my app from AppStore profiles as well as from xcode plist .

Our database is becoming inaccessible for few seconds after device reboot and first unlock due to Apple's Data Protection policy. So I am restricting any database operations with below logic when app getting launched.

if([[UIApplication sharedApplication] isProtectedDataAvailable]) {
    //access data
}else {
    // wait for applicationProtectedDataDidBecomeAvailable callback
}

I found some unexpected behavior. Even though [[UIApplication sharedApplication] isProtectedDataAvailable] is returning true, after 10~20 seconds (grace period) applicationProtectedDataDidBecomeAvailable callback is called as part of this from my above code logic, the database is accessed and failed due to actually still being protected by OS.

Is there anything I am missing? Why does iOS returning [[UIApplication sharedApplication] isProtectedDataAvailable] value as true when actually protected data are not yet available?

I am working on, Xcode 11.0, tested device OS 13.2.

Update

For some cases in log I found the [[UIApplication sharedApplication] isProtectedDataAvailable] is returning 1 but NSUserDefault still inaccessible. What can be possible reason?


isProtectedDataAvailable - The value of this property is false if data protection is enabled and the device is currently locked. The value of this property is set to true if the device is unlocked or if content protection is not enabled. When the value of this property is false, files that were assigned the complete or completeUnlessOpen protection key cannot be read or written by your app. The user must unlock the device before your app can access them. NSFileProtectionCompleteUntilFirstUserAuthentication - After the user unlocks the device for the first time, your app can access the file and continue to access it even if the user subsequently locks the device.

Paganize answered 11/12, 2019 at 9:12 Comment(7)
Are you calling the method on the main thread?Diuretic
yes on the main thread as I am calling from app delegate callbacksPaganize
I think you have to wait for some time, may be 10 seconds of grace period time after the screen is locked before the protected data is locked. You can the device console log from Xcode > Window > DevicesMaltzman
@Niraj the grace period is supposed to be handled by OS itself. Because the callback would be fired after grace period of device locked unlocked event. Should I also wait after callback fired?Paganize
do you test this feature on real device?Antipodal
Yess all the problems I mentioned here were tested with real device. @antonioPaganize
Looks like an Apple's bug. Did you report the bug?Sabrina

© 2022 - 2024 — McMap. All rights reserved.