NSURLSessionDataTask를 사용하여 요청 체인을 실행하려고합니다. 첫 번째 요청이 끝나면 주먹 요청의 responseData를 사용하여 다른 여러 요청을 실행해야합니다. 그리고 결국, NSArray를 얻고 테이블 뷰로 이동합니다. 그렇게하는 방법? 아래에서 볼 수 있듯이 작동하지 않습니다. 당신이NSURLSessionDataTask를 사용한 체인 요청
데이터를 다운로드하는 경우
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:config];
NSString *tvdbId = [[NSUserDefaults standardUserDefaults] objectForKey:@"tvdbId"];
NSURL *urlString = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.trakt.tv/show/seasons.json/%@/%@", kApiKey, tvdbId]];
__weak EpisodeViewController *weakSelf = self;
NSURLSessionDataTask *task = [manager dataTaskWithRequest:[NSURLRequest requestWithURL:urlString] completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (!error) {
NSArray *seasons = (NSArray *)responseObject;
__block NSMutableArray *seasonArray = [NSMutableArray new];
[seasons enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *seasonNumber = obj[@"season"];
NSURL *urlString = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.trakt.tv/show/season.json/%@/%@/%@", kApiKey, tvdbId, seasonNumber]];
NSURLSessionDataTask *eposideTask = [manager dataTaskWithRequest:[NSURLRequest requestWithURL:urlString] completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSArray *eposides = (NSArray *)responseObject;
NSDictionary *dict = @{@"season": seasonNumber, @"eposodes": eposides};
[seasonArray addObject:dict];
}];
[eposideTask resume];
}];
weakSelf.eposides = [NSArray arrayWithArray:seasonArray];
NSLog(@"%@", weakSelf.eposides);
}
}];
[task resume];
내 업데이트 확인 내 질문에 답할 –