I call sendSynchronousRequest in my second thread, and my second thread will be blocked, So how to get progress information in my first thread?
            Asked
            
        
        
            Active
            
        
            Viewed 580 times
        
    1 Answers
0
            
            
        You must use an asynchronous downloader on your second thread. Then use a delegate callback asynchronously!
For example:
    @protocol DownloadUIProtocol<NSObject>
    - (void)updateUI:(id)sender;
    @end
    @interface ViewController () {
      NSMutableData *receivedData_;
      NSDate *lastUpdateUITime_;
      __weak id<DownloadUIProtocol> delegate_;
    }
    @end
    ...
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
      [receivedData_ appendData:data];
      NSDate *now = [NSDate date];
      if (fabs([lastUpdateUITime_ timeIntervalSinceDate:now]) > 60) {
        dispatch_async(dispatch_get_main_queue(), ^{
          if ([delegate_ respondsToSelector:@selector(updateUI:)]) 
            [delegate_ updateUI:self];
        });
        lastUpdateUITime_ = now;
      }  
    }
        Community
        
- 1
 - 1
 
        Matt Melton
        
- 2,493
 - 19
 - 25