0
做
我如何可以等待特定的任务来完成?等待一个任务就在Xcode
这就是我想要做的事:
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%确定,连接已建立。
我想用这个作为一个很不错的选择以编程方式检查网络连接。
你是对的!我的错!你能告诉我更多关于ios中的异步任务吗? – Philip
在答案中增加了一个简单的选项。有很多选项取决于请求和响应的细节以及你将要对结果做什么... – Wain
它基本上是一个从某个URL抓取JSONArray的任务。 – Philip