-1

在我的应用程序中,收到推送通知后,我需要从服务器下载数据并在应用程序处于后台时保存到数据库中。这是我的代码

   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];      
    }];

当应用程序仅在前台时,此代码正在执行。谢谢。

4

1 回答 1

0

尝试直接使用 https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html

您也可以尝试使用 AFNetworking,它提供了一个不错的 api

于 2015-09-03T17:59:02.317 回答