Sto utilizzando PromiseKit e vorrei forzare il download sequenziale di JSON. Il conteggio dei JSON potrebbe cambiare.Utilizzo di PromiseKit per forzare il download sequenziale
Ho letto this sul concatenamento. Se avessi un numero fisso di download di dire 3, questo andrebbe bene.
Ma cosa succede se ho un conteggio variabile del download che vorrei scaricare sequenzialmente?
Questo è il mio codice per 2 URL. Mi chiedo come potrei farlo con l'iterazione dateUrlArray[i]
sull'array?
- (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");
});
});
}
Molte molte grazie per ObjC 'arrugginito' ;-) Ottima risposta, e IMHO un'omissione sul sito Promisekit. Ho fatto una piccola modifica (p dovrebbe essere di tipo PMKPromise). – brainray