伊谢尔伦2017-04-17 16:54:51
iOS开发小白一枚, 每太明白题主意思.
练习的时候还真没使用到AFJSONRequestOperation
, 一直都是用下面的作者的Demo来请求数据的
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
阿神2017-04-17 16:54:51
这样从manager来拿operation的实例是木有问题的,你可以command+鼠标,点进去看看manager对operation做了拿些配置。他最后也是把operation添加到operationQueue里面来开始任务的,而不是直接用的start
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.requestSerializer = [AFJSONRequestSerializer serializer];
AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSInteger statusCode = operation.response.statusCode;
//...
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSInteger statusCode = operation.response.statusCode;
//...
}];
[manager.operationQueue addOperation:operation];