错误域=NSURLError域代码=-1009 "The Internet connection appears to be offline."



当我尝试使用以下代码连接到soundcloud时:

// Create the request.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://soundcloud.com/api"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];
// Create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

虽然我得到以下错误:

Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x14cfccae0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "The Internet connection appears to be offline." UserInfo={NSErrorFailingURLStringKey=https://soundcloud.com/api, NSErrorFailingURLKey=https://soundcloud.com/api, kCFStreamErrorCodeKey=50, kCFStreamErrorDomainKey=1, NSLocalizedDescription=The Internet connection appears to be offline.}}, NSErrorFailingURLStringKey=https://soundcloud.com/api, NSErrorFailingURLKey=https://soundcloud.com/api, kCFStreamErrorDomainKey=1, kCFStreamErrorCodeKey=50, NSLocalizedDescription=The Internet connection appears to be offline.}

关键是:我在我的iPhone上运行它,网络是4G。当我通过 Wifi 使用其他网络时,代码实际上运行良好。

原因是我的iPhone上的应用程序关闭了4G网络,但不确定我何时以及为什么这样做。

我找到了解决方案,因为它设置了超时间隔:10.0在

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://soundcloud.com/api"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];

并且在此时间内没有收到响应,因此您需要超过此时间,或者您也可以删除此间隔

通过更新我的 MacOS 删除了错误...

相关内容

最新更新