【发布时间】:2015-08-21 21:58:01
【问题描述】:
我正在使用 PromiseKit,并希望强制顺序下载 JSON。 JSON 的数量可能会发生变化。
我已经阅读了this 关于链接的内容。 如果我有固定数量的下载量,比如 3 次,那就没问题了。
但是,如果我想按顺序下载不断变化的下载次数怎么办?
这是我的 2 个 URL 的代码。我想知道如何通过数组上的dateUrlArray[i] 迭代来做到这一点?
- (void)downloadJSONWithPromiseKitDateArray:(NSMutableArray *)dateUrlArray {
[self.operationManager GET:dateUrlArray[0]
parameters:nil]
.then(^(id responseObject, AFHTTPRequestOperation *operation) {
NSDictionary *resultDictionary = (NSDictionary *) responseObject;
Menu *menu = [JsonMapper mapMenuFromDictionary:resultDictionary];
if (menu) {
[[DataAccess instance] addMenuToRealm:menu];
}
return [self.operationManager GET:dateUrlArray[1]
parameters:nil];
}).then(^(id responseObject, AFHTTPRequestOperation *operation) {
NSDictionary *resultDictionary = (NSDictionary *) responseObject;
Menu *menu = [JsonMapper mapMenuFromDictionary:resultDictionary];
if (menu) {
[[DataAccess instance] addMenuToRealm:menu];
}
})
.catch(^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self handleCatchwithError:error];
});
}).finally(^{
dispatch_async(dispatch_get_main_queue(), ^{
DDLogInfo(@".....finally");
});
});
}
【问题讨论】:
标签: ios objective-c promise promisekit