我正在为我的项目使用AFNetworking 2.0.我很简单 向服务器发送一些请求,服务器返回一些 JSON 我. 为了测试它,我在成功块中标记了一些调试标记 AFNetworking POST方法.问题是当应用程序在 前景
          向服务器发送一些请求,服务器返回一些 JSON
我.
>为了测试它,我在成功块中标记了一些调试标记
AFNetworking POST方法.问题是当应用程序在
前景,当应用程序收到服务器的响应时,
xCode可以在成功和失败块中的调试标记处停止.
但是当我提出请求时,请将应用程序带到后台(按
主页按钮),调试永远不会进入块.
>看起来他们在应用程序处于后台时暂停了,因为
当应用程序再次处于前台时,调试立即进入
块我得到了回应.
我错过了什么吗?因为我希望应用程序接收响应并做一些事情,即使它在后台.
这是我在我的应用中使用的内容:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = /*generate the parameters*/;
NSURL *filePath = [NSURL fileURLWithPath:@"imageName.png"];
[manager POST:@"http://example.com/resources.json" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    [formData appendPartWithFileURL:filePath name:@"image" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Success: %@", responseObject);
//debug here
//Told the app to stop the Loading View, save response to DB
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
//debug here
//Told the app to stop the Loading View and try again sometimes
}];
 这是我的坏事.我忘了告诉应用程序在进入后台时继续运行.我将这些代码添加到我的项目中: 
  
  
 UIBackgroundTaskIdentifier backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
}]; 
 当应用程序进入后台时:
[[UIApplicatioz sharedApplication] endBackgroundTask:backgroundTask];
