Find the line where you are running databaseWithPath: (or initWithPath: , then add:
FMDatabase *db = [FMDatabase databaseWithPath:path]; NSDictionary *attributes = @{NSFileProtectionKey: NSFileProtectionCompleteUnlessOpen}; NSError *error; BOOL success = [[NSFileManager defaultManager] setAttributes:attributes ofItemAtPath:path error:&error]; if (!success) { NSLog(@"File protection failed: %@", error); }
possible values for the NSFileProtectionKey key:
NSFileProtectionNone : The file does not have specific protections associated with it. It can be read or written at any time.NSFileProtectionComplete : The file is stored in an encrypted format on disk and cannot be read or written while the device is locked or loaded.NSFileProtectionCompleteUnlessOpen : The file is encrypted on disk. Files can be created when the device is locked, but after closing it cannot be opened again until the device is unlocked. If the file opens when unlocking, you can continue to access the file in normal mode, even if the user locks the device. There is a slight performance limitation when creating and opening a file, although not when writing or reading. This can be mitigated by changing the file protection to NSFileProtectionComplete when the device is unlocked.NSFileProtectionCompleteUntilFirstUserAuthentication : The file is encrypted on disk and cannot be accessed until the device boots. After the user first opens the device, your application can access the file and continue to access it, even if the user subsequently locks the device.
The correct type of protection may depend on the version of iOS (the last two are not available on iOS 4) and whether you use your database when the device is locked.
source share