Wednesday, May 22, 2013

UIApplication protectedDataAvailable example ios


[UIApplication protectedDataAvailable]

A Boolean value indicating whether content protection is active. (read-only)
@property(nonatomic, readonly, getter=isProtectedDataAvailable) BOOL protectedDataAvailable
Discussion of [UIApplication protectedDataAvailable]
The value of this property is NO if content protection is enabled and the device is currently locked. The value of this property is set to YES if the device is unlocked or if content protection is not enabled.[UIApplication protectedDataAvailable]
When the value of this property is NO, files that were assigned theNSFileProtectionComplete protection key cannot be read or written by your application. The user must unlock the device before your application can access them.
Example of [UIApplication protectedDataAvailable]
[self performSelector:@selector(doReload) withObject:nil afterDelay:20];

- (void)doReload {

    NSLog(@"protected data available: %@",[UIApplication sharedApplication].protectedDataAvailable ? @"yes" : @"no");

    NSError *error;

    self.fileContents = [NSString stringWithContentsOfFile:[self filePath]
                                              encoding:NSUTF8StringEncoding
                                                 error:NULL];

    NSLog(@"file contents: %@\nerror: %@", self.fileContents, error);
}