0
嗨读取数据,所以我想从这个网站检索数据:对于我正在一个应用程序http://www.timeapi.org/utc/now,但是当我提出用下面的代码的要求,我总是得到空:错误从网站
NSURL * timeAPI = [[NSURL alloc]initWithString:@"http://www.timeapi.org/utc/now"];
NSURLRequest * urlRequest = [[NSURLRequest alloc]initWithURL:timeAPI];
__block NSData * responseData;
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if(connectionError)
{
NSLog(@"error fetching data");
}
else{
responseData = [[NSData alloc]initWithData:data];
}
}];
NSError* error = nil;
NSLog(@"%@, erorr:", responseData);
任何人都可以找出问题吗?
谢谢!我会做出改变;另外,我如何解决使用块声明?如果我不使用它,那么它说我错过了块标识符。 – user1549792
在完成块中将数据保存到某个属性或放入通知中。使用self来设置属性是很好的,因为该块不是由self引用的。 – zaph