[NSURLConnection connectionWithRequest:req delegate:self];
,然后我用
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace;
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
-(void)connectionDidFinishLoading:(NSURLConnection *)connection;
来处理数据加载。一切正常,工作正常,但我不喜欢这个代码之美)
我希望用块,使我的代码看起来是这样的:
[myConnection sendData:data
successBlock:^(void){NSLog(@"success");}
errorBlock:^(NSError * error){NSLog(@"error.description: %@", error.description);}];
是有可能使用NSURLConnection的使用块?
谢谢jcesar,它的工作)非常感谢! – Nils 2013-02-17 07:37:17
这看起来很奇怪。如果您在对象上调用另一个请求,则可能会覆盖完成块... – Tudorizer 2013-04-17 16:15:36
感谢您的帮助。 Tudorizer,你需要为新的请求创建新的实例。 – Segabond 2013-09-03 10:10:53