I am using sqlite DB to save data.i want to save apps state lifecycle of the app. for that i used sqlite .i have created table with two colums . i am i am able to save data also. but some time i am getting this error DB Error: unknown error .
**DB Error: unknown error**
Could not execute the query.
-(void)saveInfo{
// Prepare the query string.
NSString *query = [NSString stringWithFormat:@"insert into processInfo values(null, '%@', '%@')", _timeFormatter, _process];
// Execute the query.
[self.dbManager executeQuery:query];
// If the query was successfully executed then pop the view controller.
if (self.dbManager.affectedRows != 0) {
NSLog(@"Query was executed successfully. Affected rows = %d", self.dbManager.affectedRows);
}
else{
NSLog(@"Could not execute the query.");
}
}
- (void)dateAndTime {
if(!self.dateFormatter) {
self.dateFormatter = [[NSDateFormatter alloc] init];
}
[self.dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
}
//call back
static void displayStatusChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
// the "com.apple.springboard.lockcomplete" notification will always come after the "com.apple.springboard.lockstate" notification
CFStringRef nameCFString = (CFStringRef)name;
NSString *lockState = (__bridge NSString*)nameCFString;
NSLog(@"Darwin notification NAME = %@",name);
if([lockState isEqualToString:@"com.apple.springboard.lockcomplete"])
{
NSLog(@"DEVICE LOCKED");
//Logic to disable the GPS
}
else
{
NSLog(@"LOCK STATUS CHANGED");
//Logic to enable the GPS
}
}
-(void)registerforDeviceLockNotif
{
//Screen lock notifications
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.lockcomplete"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.lockstate"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
}
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(@"\t ----- App will tResignActive %@ -------",[self.dateFormatter stringFromDate:[NSDate date]]);
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"\t ----- App in Background at %@ -------",[self.dateFormatter stringFromDate:[NSDate date]]);
_timeFormatter=[self.dateFormatter stringFromDate:[NSDate date]];
_process=@"Background";
[self saveInfo];
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"\t ----- App in Forground %@ -------",[self.dateFormatter stringFromDate:[NSDate date]]);
_timeFormatter=[self.dateFormatter stringFromDate:[NSDate date]];
_process=@"Forground";
[self saveInfo];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"\t ----- App will tResignActive %@ -------",[self.dateFormatter stringFromDate:[NSDate date]]);
[self saveInfo];
}
- (void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"\t ----- App will terminate %@ -------",[self.dateFormatter stringFromDate:[NSDate date]]);
_timeFormatter=[self.dateFormatter stringFromDate:[NSDate date]];
_process=@"terminate";
[self saveInfo];
}
Aucun commentaire:
Enregistrer un commentaire