title: Receive push when app is closed
body: <p>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.</p>
  
  <p>how can I save data from push notification to sqlite db when the app is completely closed and not in the background .</p>
  
  <p>i need to do this code while the application is closed and receives a push notification</p>
  
  <pre><code>- (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 .... %@ ---- &gt; %@",key,data); 
  
      }
  
      query = [NSString stringWithFormat:@"INSERT INTO accounts(email_address) VALUES ('%@')",data;
      sqlite3_stmt *compiledStatement;
      if(sqlite3_prepare_v2(mydb, [query UTF8String], -1, &amp;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));
      }
  } 
  </code></pre>