fileExistsAtPath
和checkResourceIsReachableAndReturnError
都返回NO
,即使文件存在于服务器URL
中。
我在(本地)服务器中有一个文件,在http://10.0.0.15/images/hibrise.png
中。
NSURL *url=[NSURL URLWithString:@"http://10.0.0.15/images/hibrise.png"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[url path]];
NSLog(fileExists ? @"Yes" : @"No");
我已经检查了文件权限,一切正常。当我在浏览器中输入相同的URL时,它会显示图像。
'fileExistsAtPath'是用于检查内部文件系统中文件可用性的方法。
'checkResourceIsReachableAndReturnError'也仅适用于内部iOS文件系统。
此方法目前仅适用于文件系统资源的URL。对于其他URL类型,将返回NO
苹果公司也同样适用于'fileExistsAtPath'。最好的方法是使用URL来检查文件是否可用。