开发者

NSURLConnection redirect pause

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜