I am trying to save a data that comes with push notification payload. It works well when the app is running but not when the app is closed.
how can I save data from push notification to sqlite db when the app is completely closed and not in the background .
i need to do this code while the application is closed and receives a push notification
- (void) application:(UIApplication *)application didReceiveRemoteNotification:NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//save data
NSLog(@" Received remote notifcation: %@", userInfo);
for (NSString *key in [userInfo allKeys])
{
NSString *data = [userInfo objectForKey:key];
NSLog(@"inside did register for notification .... %@ ---- > %@",key,data);
}
query = [NSString stringWithFormat:@"INSERT INTO accounts(email_address) VALUES ('%@')",data;
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(mydb, [query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
if(SQLITE_DONE != sqlite3_step(compiledStatement))
{
NSLog( @"Error while inserting data: '%s'", sqlite3_errmsg(mydb));
}
else {
NSLog(@"New data inserted");
isneed=@"yes";
}
sqlite3_reset(compiledStatement);
}
else
{
NSLog( @"Error while inserting '%s'", sqlite3_errmsg(mydb));
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…