ios NSURLConnection 的错误代码“-1009”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6689407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does NSURLConnection's error code "-1009" mean?
提问by jxx
When I send a request and get an error with the error code -1009
, what does that mean? I'm not sure how to handle it.
当我发送请求并收到带有错误代码的错误时-1009
,这是什么意思?我不知道如何处理它。
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"connection didFailWithError");
if(error.code==-1009){
//do something
}
}
回答by DarkDust
Since the error returned should be within the NSURLErrorDomain
, the code -1009
means:
由于返回的错误应该在 内NSURLErrorDomain
,代码的-1009
意思是:
NSURLErrorNotConnectedToInternet
Returned when a network resource was requested, but an internet connection is not established and cannot be established automatically, either through a lack of connectivity, or by the user's choice not to make a network connection automatically.
NSURLErrorNotConnectedToInternet
当请求网络资源但未建立 Internet 连接并且无法自动建立时返回,这可能是由于缺乏连接或用户选择不自动建立网络连接。
回答by ricardopereira
With Swift, you can use the NSURLError
enum for NSURL error domain check:
使用Swift,您可以使用NSURLError
枚举进行 NSURL 错误域检查:
switch NSURLError(rawValue: error.code) {
case .Some(.NotConnectedToInternet):
print("NotConnectedToInternet")
default: break
}
Swift 3:
斯威夫特 3:
switch URLError.Code(rawValue: error.code) {
case .some(.notConnectedToInternet):
print("NotConnectedToInternet")
default: break
}
Swift 4:
斯威夫特 4:
switch URLError.Code(rawValue: error.code) {
case .notConnectedToInternet:
print("NotConnectedToInternet")
default: break
}
回答by Morten Fast
It's NSURLErrorNotConnectedToInternet
which means, well, that you're not connected to the internet... :)
这NSURLErrorNotConnectedToInternet
意味着,嗯,你没有连接到互联网...... :)
You can find the error codes in NSURLError.h
.
您可以在 中找到错误代码NSURLError.h
。