iphone - controlling order of received data in NSURLConnection? -
i have array of urls use receive associated images remote server using nsurlconnection
nsurl *url = [nsurl urlwithstring:urlstring]; nsmutableurlrequest *urlrequest = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:2.0f]; // run network request asynchronously nsurlconnection *urlconnection = [[nsurlconnection alloc] initwithrequest:urlrequest delegate:self];
in delegate protocol
- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { // chuncks of image received, build our data file [self.imagedata appenddata:data]; }
and
- (void)connectiondidfinishloading:(nsurlconnection *)connection { // data has been downloaded, can set image in images array _img = [uiimage imagewithdata:self.imagedata]; [self.imagesarray insertobject:_img atindex:_index]; [self.imagedata setlength:0]; _index = _index+ 1; }
but order of received not same order of sending url request tried using instance variable index insert these images in same order in images array not work , still getting unordered listings , point me in right direction how achieve this.
in general if downloading images rely on excellent afnetworking classes. http://afnetworking.com provides overall behavior looking (one takes uiimageview, , default image, deliver image bytes)
if there reason must make own, have dictionary of download name nsurlconnection. allow figure out download has asynchronously completed, , act correctly on it.
if mean synchronous delivery of download objects, dispatch them 1 @ time, wait response, , start next on completion.
Comments
Post a Comment