Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You use the <a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/c/data/NSFileProtectionComplete" rel="nofollow">NSFileProtectionComplete</a> feature (it's only available in ios 4 and greater).</p> <p>Here is an example of creating a NSPersistentStoreCoordinator for example.sqlite which is encrypted if used on ios4.</p> <pre><code>- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"example.sqlite"]; NSURL *storeUrl = [NSURL fileURLWithPath:storePath ]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&amp;error]) { // Handle error } if(RSRunningOnOS4OrBetter()) { NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey]; if (![[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:storePath error:&amp;error]) { // Handle error } } return persistentStoreCoordinator; } BOOL RSRunningOnOS4OrBetter(void) { static BOOL didCheckIfOnOS4 = NO; static BOOL runningOnOS4OrBetter = NO; if (!didCheckIfOnOS4) { NSString *systemVersion = [UIDevice currentDevice].systemVersion; NSInteger majorSystemVersion = 3; if (systemVersion != nil &amp;&amp; [systemVersion length] &gt; 0) { //Can't imagine it would be empty, but. NSString *firstCharacter = [systemVersion substringToIndex:1]; majorSystemVersion = [firstCharacter integerValue]; } runningOnOS4OrBetter = (majorSystemVersion &gt;= 4); didCheckIfOnOS4 = YES; } return runningOnOS4OrBetter; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload