ios - AFImageRequestOperation in order not asynchronous -


i implementing code downloads images , saves them in database of app,

i have array of objects, each object contains image url , other information. download images i'm using class library afimagerequestoperation.h afnetworking.

my code downloads , saves data in database, need notify user image downloaded, eg: if have array containing 5 objects (quoted above each object), have downloading same order in array, afimagerequestoperation makes downloading asynchronously item 4 can downloaded before first item.

in short, want have control , release next download when previous 1 completed.

i have runs through array of objects , calls function each position, function has following code:

nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:[arrimagem valueforkey:@"urlimagem"]]];     afimagerequestoperation *operation = [afimagerequestoperation imagerequestoperationwithrequest:request imageprocessingblock:nil success:^(nsurlrequest *request, nshttpurlresponse *response, uiimage *image){          imagens *imagem = (imagens *)[nsentitydescription insertnewobjectforentityforname:@"imagens" inmanagedobjectcontext:managedobjectcontext];          // save image         nsdata *imagedata = uiimagejpegrepresentation(image, 90);         [imagem setcategoria:cat];         [imagem settitulo:[arrimagem valueforkey:@"titulo"]];         [imagem setdescricao:[arrimagem valueforkey:@"descricao"]];         [imagem setimagem:imagedata];            nserror *error;         if(![managedobjectcontext save:&error]){             nslog(@"houve um erro muito grave");             //return false;         }else{             nslog(@"salvou imagem");         }      }failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error){         nslog(@"%@", [error localizeddescription]);      }];      [operation start]; 

i not know if question clear, question similar link

afimagerequestoperation subclass of nsoperation can use:

- (void) adddependency: (nsoperation*) operation 

to make sure 1 operation finishes before other.

for example:

nsoperation *op1 = [[nsoperation alloc]init]; nsoperation *op2 = [[nsoperation alloc]init];  [op1 adddependency: op2]; 

this way op1 won't start before op2 finished.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -