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 */
}];
精彩评论