core data - How can I find out if the iPhone user currently has a passcode set and encryption enabled? -
I am writing an iPhone application that needs to be encrypted. I have learned how to set the NSFileProtectionComplete attribute To have encryption turned on. I also know how to check the iPhone version to ensure that iOS 4.0 or better is going.
Whatever I have realized, if the user has not chosen a passcode and especially on data protection settings> normal> passcode lock screen then the data is not exactly safe at all.
I would like to pop up a warning and tell the user that they have to enable the passcode and have to turn on data protection (where backup is required and restored on the pre-4 iphone), And then exit the application if they do not have passcode and data protection enabled. However I can not understand the status of these settings anyway. I have found all APIs in UIApplication, such as "Protected DataAvap", with the success all pass if data protection is disabled.
Disclaimer: This reply was valid until IOS 4.3.3
If data protection is on, then in a newly created file, zero
NSFileProtectionKey
.
If the data protection is off, then a new file will have NSFileProtectionNone
NSFileProtectionKey
by default.
In this way, you can detect the presence of file security with the following code:
NSString * tmpDirectoryPath = [NSHomeDirectory (stringByPantingPathCompany: @ "TMP"]]; NSString * testFilePath = [tmpDirectoryPath stringbapping path comparison: @ "testfile"]; [@ "" instrument file: testFilePath atom: yes encoding: NSUTF8 string encoding error: NULL]; // Clearly, better error handle NSDictionary * testFileAttributes = [[NSFileManager defaultManager ] AttributesOfItemAtPath: testFile1Path error: NULL]; BOOL file security Additive = [NSFileProtectionNoneEqualToString: [testFile1 object objectForKey: NSFileProtectionKey]];
Comments
Post a Comment