1
我正在与AFNetworking从网上获取一些JSON。我如何获得返回的异步请求的响应?这里是我的代码:等待AFJSONRequestOperation完成
- (id) descargarEncuestasParaCliente:(NSString *)id_client{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://whatever.com/api/&id_cliente=%@", id_client]]];
__block id RESPONSE;
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
RESPONSE = JSON;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"ERROR: %@", error);
}];
[operation start];
return RESPONSE;
}
感谢您的示例代码!但是,在这种情况下,函数的返回类型是否会变为void? –
你绝对正确 –
我是这么想的。你的实现确实有效。非常感谢! :) –