Assyncrhonous download


/ Published in: Objective C
Save to your folder(s)

It was based in Markjnet example here:
>> http://www.markj.net/iphone-asynchronous-table-image/


Copy this code and paste it in your HTML
  1. // *.h
  2. NSURLConnection* connection;
  3.  
  4. =======
  5.  
  6. // *.m
  7.  
  8. - (void)viewWillAppear:(BOOL)animated {
  9.  
  10. // request the data
  11. NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.img] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
  12. connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  13.  
  14. }
  15.  
  16. - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
  17. if (data==nil) {
  18. data = [[NSMutableData alloc] initWithCapacity:2048];
  19. }
  20. [data appendData:incrementalData];
  21. }
  22.  
  23. - (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
  24.  
  25. [connection release];
  26. connection=nil;
  27.  
  28. // do the stuff with your downloaded data here
  29.  
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.