开发者

NSURLConnection redirect pause

开发者 https://www.devze.com 2023-02-12 06:18 出处:网络
I currently have a NSURLConnection to a site that does a bunch of redirects NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];

I currently have a NSURLConnection to a site that does a bunch of redirects

  NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
  if (theConnection) {
    receivedData = [[NSMutableData data] retain];
  } else {
    NSLog(@"Connection failed");
  }

I would like pause in between the redirects without pausing the main 开发者_如何学编程thread, as I do now. Any suggestions? Thanks.

- (NSURLRequest *)connection: (NSURLConnection *)inConnection
             willSendRequest: (NSURLRequest *)inRequest
            redirectResponse: (NSURLResponse *)inRedirectResponse;
{
  [NSThread sleepForTimeInterval:3];
  return inRequest;
}


You can use GCD:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC),
               dispatch_get_main_queue(), ^{
  /* Your code */
}];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号