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? –
你絕對正確 –
我是這麼想的。你的實現確實有效。非常感謝! :) –