In the device settings,AutoLock is 5 minutes, and Passcode Lock is Immediatly.
Suppose user clicked the power button of device when application is processing a large xml from server and insert/update database file. (the device will be in a locaked state when user click power button) When the device is locked, we are seeing the errors like
failed to CREATE statement with message 'unable to open database file'.' or disk I/O error
We are performing sqlite3_step, sqlite3_exec, sqlite3_prepare_v2 operations when process xml.
tried these..
- open database file when application launches and close when application terminates. So we we can keep the database open when user lock the device..
below is the source code to open database file, this is the code in application delegate class to return the database file. We are calling this method from different classes. databasemain is the instance of sqlite3 * declared in AplicationDelegate.h file.
- (sqlite3 *) getMainDatabase{
if(databasemain == nil){
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"mydb.sqlite"];
if (sqlite3_open_v2([dbPath UTF8String], &databasemain, SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_FILEPROTECTION_COMPLETEUNLESSOPEN, NULL) == SQLITE_OK){
}else{
MyLogAll(@"db not opened");
}
}
return databasemain;
}
Also tried with SQLITE_OPEN_FILEPROTECTION_NONE, but no change..
Also tried with no encryption parameter
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
}
in the device lock state, also loosing the values stored in NSUserDefaults.
Please share your experience to guide me the right direction.
Looking for a way to handle this situation of immediate passcode lock..