I am using file security using NSFileProtectionKey attribute like this:
[[NSFileManager defaultManager] setAttributes:@{NSFileProtectionKey : NSFileProtectionComplete} ofItemAtPath:coreDataFilePath error:NULL];
So, no file in that path can be opened when device is passcode locked. The problem is that from iOS7 Apps can run in the background even while device is locked. When running like that Coredata [NSManagedObjectContext save:]
will fail with error:
NSCocoaErrorDomain, 134030, The operation couldn’t be completed. (Cocoa error 134030.) { NSSQLiteErrorDomain = 23; NSUnderlyingException = "Updating max pk failed: authorization denied"; }
How to handle such case?
First, see Session 204 "What's New with Multitasking" from the WWDC 2013 videos. It covers this case.
There are several approaches you can take, in order of security preference:
NSFileProtectionCompleteUnlessOpen
) until the device is unlocked, then merge. This is generally the preferred approach.NSFileProtectionCompleteUnlessOpen
and keep it open.NSFileProtectionCompleteUntilFirstUserAuthentication
. This is generally the worst approach.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With