Wednesday 15 January 2020

isProtectedDataAvailable is returning true always in iOS

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.


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.



from isProtectedDataAvailable is returning true always in iOS

No comments:

Post a Comment