Overcoming unexpected behavior of NSURL's checkResourceIsReachableAndReturnError

最后都变了- 提交于 2019-12-12 10:48:15

问题


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");
}

Further, I tried:

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");
}

...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?


回答1:


The Apple docs for checkResourceIsReachableAndReturnError: state:

Returns whether the resource pointed to by a file URL can be reached.

Note: "file URL", not Internet or other scheme URL.



来源:https://stackoverflow.com/questions/9266154/overcoming-unexpected-behavior-of-nsurls-checkresourceisreachableandreturnerror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!