开发者

Need complete Data protection while Core Data processing is in background

I am just stuck in the middle of the project.

My objective is to protect my data.

I have gone thr开发者_C百科ough Nickharris blog regarding (Core Data and Enterprise iPhone Applications – Protecting Your Data)

But in the conclusion it is clearly mentioned that:

If your application needs your Core Data store in any background processing, then you cannot use data protection. Any attempt to access files that are NSFileProtectionComplete will cause an exception.

And I am using core data in background processing.

Please help regarding this. I want to encrypt and protect my data anyhow

Thanks, Tariq


On iOS 5 you can use either one, but there is still a catch for each of them.

  1. NSFileProtectionCompleteUnlessOpen - The file is stored in an encrypted format on disk and must be opened while the device is unlocked. Once open, your file may continue to access the file normally, even if the user locks the device.

  2. NSFileProtectionCompleteUntilFirstUserAuthentication - The file is stored in an encrypted format on disk and cannot be accessed until after the device has booted. After the user unlocks the device for the first time, your application can access the file and continue to access it even if the user subsequently locks the device.

Source: iOS Developer Library


According to the documentation NSFileProtectionComplete dictates that the file cannot be read from or written to while the application is in the background (or not running).

You should be fine to read / write the SQLite store while the application is running, however you will not have access to it while it is in the "background".

This means that operations which leverage the iOS background APIs like:

  • Push notifications
  • Background Audio / Location
  • Task completion (Background)
  • Voice Over IP

Will not have access to your SQLite store. When the app is running however you should be able to access the NSPersistentStoreCoordinator as you normally would. I suspect that a device side test would result in a failure to create the persistent store coordinator from one of the background APIs.


Make your file access calls in the main thread - there's a really useful method on NSObject that should help you :)

// When you need to get the data from the file do this :
NSData *data = [self performSelectorInMainThread:@selector(getFileData:) withObject:filename waitUntilDone:YES];


// And somewhere else in your class have this method
- (NSData *)getFileData:(NSString *)filename {
    ...
    // Get data from file and return it
    ....
}

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜