-1

In my application , After receving push notification I need to download data from server and saved into database when application is in back ground. here is my code

   NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
   NSURLRequest *request = [NSURLRequest requestWithURL:Url];
   [NSURLConnection sendAsynchronousRequest:request
                                   queue:myQueue
                       completionHandler:^(NSURLResponse *response, 
   NSData *data, NSError *error){
     [self saveDataIntoDB:data];      
    }];

This code is excuting when application is in foreground only. Thanks.

  • According to documentation you would be given only minimum time to perform your actions like saving the status of any current process at the time of application ging to the background to resume when it comes to frground – vignesh kumar Sep 03 '15 at 17:41

1 Answers1

0

Try using directly https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html

You can try using AFNetworking as well which provides a nice api

Avner Barr
  • 13,049
  • 14
  • 82
  • 152