克服 NSURL 的 checkResourceIsReachableAndReturnError 的意外行为 [英] Overcoming unexpected behavior of NSURL's checkResourceIsReachableAndReturnError
问题描述
在我为 iOS 5 创建的程序中,我遇到了 NSURL 的 checkResourceIsReachableAndReturnError 方法的意外行为.
In a program I am creating for iOS 5, I am experiencing unexpected behavior with the checkResourceIsReachableAndReturnError method of NSURL.
我创建了一个新项目来验证问题并且只包含代码:
I created a new project to verify the issue and included only the code:
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
NSError *err = nil;
if([url checkResourceIsReachableAndReturnError:&err]){
NSLog(@"URL is reachable");
}else {
NSLog(@"URL is not reachable");
}
进一步,我试过:
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
NSError *err = nil;
[url checkResourceIsReachableAndReturnError:&err];
if(err == nil){
NSLog(@"URL is reachable");
}else {
NSLog(@"URL is not reachable");
}
...仍然无济于事.结果总是URL 无法访问",这与 stackoverflow.com(以及我测试的其他域)显然可以访问相反.如何利用这个函数来检查资源是否可达?
...still to no avail. The result is always, "URL is not reachable", contrary to stackoverflow.com (and other domains I tested) obviously being reachable. How does one utilize this function to check if a resource is reachable?
推荐答案
Apple 文档 checkResourceIsReachableAndReturnError:
状态:
Returns whether the resource pointed to by a file URL can be reached.
注意:文件 URL",而不是 Internet 或其他方案 URL.
Note: "file URL", not Internet or other scheme URL.
这篇关于克服 NSURL 的 checkResourceIsReachableAndReturnError 的意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!