我使用以下代码检测文件是否存在。该文件确实存在,但fileExistsAtPath始终返回false
if let receiptFound = receiptUrl?.checkResourceIsReachableAndReturnError(error){
print("receiptUrl is \(receiptUrl?.path)") }
print("Does the file exist \(NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!))")
if NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!)
{ //work with file
}
我的输出是:
我无法理解为什么当文件存在时语句返回为false?
答案 0 :(得分:3)
在我看来,您正在搞乱的网址是在应用程序沙箱之外。
您的应用只能访问数量非常有限的目录(部分应用包,文档,缓存和其他一些文件夹)。文件管理器可能无法访问StoreKit目录,因此函数fileExistsAtPath
返回false。
请注意,路径的开头是/private
。这是一个强有力的迹象表明该文件不能像您这样的第三方应用程序访问。