如果你不再同时下载大量物品,并再次提出简单的全球培训要求,最容易的方法就是向全球的一个问题发出同步要求:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// There will be response data in response now, like the http status code
// etc. You should check this information to make sure you didn t get a 404
// or some other http status error
if( result ) {
// you have a good result, do something with it like create a new object or
// pass it to a method on this object, etc.
dispatch_async(dispatch_get_main_queue(), ^{
[self doSomethingWithResponseData:result];
});
} else {
// You got an error making the connection, so handle it
NSLog(@"Error making connection: %@", error);
}
});
** 说明:这一样本代码使用全球疫苗,因此只能从Snow Leopard(10.6)或更糟。 如果你需要瞄准“ Leopard”或“猛虎组织”,那么你可以使用已派遣的read光挑选器,但不能像在网上。