小编Joz*_*low的帖子

AFNetworking 2.0 - 当应用程序在后台时,请求不会成功阻止

  • 我正在为我的项目使用AFNetworking 2.0.我只是向服务器发送一些请求并且服务器为我返回一些JSON,这很简单.
  • 为了测试它,我在AFNetworking POST方法的成功块中标记了一些调试标记.问题是当应用程序位于前台并且应用程序从服务器接收响应时,xCode可以停止在成功和失败块中的调试标记处.但是当我提出请求然后将应用程序带到后台(按Home键)时,调试永远不会进入块.
  • 看起来他们在应用程序处于后台时暂停了,因为当应用程序再次处于前台时,调试会立即进入块状态并得到响应.

我错过了什么吗?因为我希望应用程序接收响应并做一些事情,即使它在后台.这是我在我的应用中使用的内容:

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

}];
Run Code Online (Sandbox Code Playgroud)

ios afnetworking-2

3
推荐指数
1
解决办法
859
查看次数

标签 统计

afnetworking-2 ×1

ios ×1