Sunday, 15 May 2011

objective c blocks - How can I use multiple AFJSONRequestOperations and combine the results into a single NSDictionary? -



objective c blocks - How can I use multiple AFJSONRequestOperations and combine the results into a single NSDictionary? -

i'm not sure if have 2 problems here or one. i'm trying download multiple json files google calendar api , combine results single nsdictionary or nsmutabledictionary.

client = [[afhttpclient alloc] init]; [client.operationqueue setmaxconcurrentoperationcount:1]; eventdata = [nsmutabledictionary dictionary]; nsmutablearray *operations = [[nsmutablearray alloc] init]; (int = 0; < calendars.count; i++){ nsstring *calendarid = [calendars objectatindex:i]; nsstring *urlstring = [nsstring stringwithformat:@"https://www.googleapis.com/calendar/v3/calendars/%@/events?key=%@&singleevents=true&orderby=starttime",calendarid,apikey]; nsurl *url = [nsurl urlwithstring:urlstring]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; afjsonrequestoperation *operation = [afjsonrequestoperation jsonrequestoperationwithrequest:request success:^(nsurlrequest *request, nshttpurlresponse *response, id json) { nsdictionary *add = json; [eventdata addentriesfromdictionary:add]; if (i == calendars.count-1) { [self parsedata]; } } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error, id json) { nslog(@"afjsonrequest failed request: %@, , error: %@",request, error); }]; [operations addobject:operation]; } [client enqueuebatchofhttprequestoperationswithrequests:operations progressblock:nil completionblock:^(nsarray *operations) { nslog(@"done"); }];

the afjsonrequestoperations in code never executes. i've had luck getting them execute placing them in nsoperationqueue instead of afhttpclient en batch, don't have info in 1 dictionary, lastly executed one. plus don't have nice progress , completion blocks on afhttpclient assumed utilize this.

would getting afhttpclient operationqueue work prepare problem of combining multiple dictionaries asynchronously?

use

[operation start];

to start afjsonrequestoperation

nsdictionary objective-c-blocks afnetworking nsoperationqueue afjsonrequestoperation

No comments:

Post a Comment