Search code examples
iosxcodecallbackappdelegatedata-protection

Difference between applicationProtectedDataDidBecomeAvailable callback and UIApplicationProtectedDataDidBecomeAvailable notification


While working in an iOS app, I found two ways to detect protected data available incident. One using callbacks and other using notifications. I need to know if they provide exact same functionalities or not. From the documentation I am unable to differentiate. So,

What are the differences between,

- (void) applicationProtectedDataDidBecomeAvailable:(UIApplication *)application {}

callback and

UIApplicationProtectedDataDidBecomeAvailable

notification?


applicationProtectedDataDidBecomeAvailable - On a device that uses content protection, protected files are stored in an encrypted form and made available only at certain times, usually when the device is unlocked. This notification lets your app know that the device is now unlocked and that you may access certain types of protected files again.

UIApplicationProtectedDataDidBecomeAvailable - Posted when the protected files become available for your code to access.


Solution

  • They provide the identical functionalities. applicationProtectedDataDidBecomeAvailable is a UIApplicationDelegate method, and UIApplicationProtectedDataDidBecomeAvailable is a NSNotification Name.

    An analogy is applicationDidBecomeActive: and UIApplicationDidBecomeActiveNotification, the former is a delegate method will be called when become active, meanwhile the latter will be post.