【发布时间】:2014-05-07 18:12:47
【问题描述】:
如何等待某项任务完成?
这就是我想要做的:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringURL]];
if (!data) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@", NOCONNECTIONALERTTITLE] message:[NSString stringWithFormat:@"%@", NOCONNECTIONALERTMESSAGE] delegate:self cancelButtonTitle:[NSString stringWithFormat:@"%@", NOCONNECTIONALERTCANCELBUTTON] otherButtonTitles:nil, nil];
[alert show];
} else { ... }
这个if 总是假的,因为它在数据初始化之前被调用。我 100% 确定连接已建立。
我想用它作为以编程方式检查互联网连接的简单替代方法。
【问题讨论】:
标签: objective-c nsdata nsurl