我有一个将图像存储到documentDirectory的应用程序。但是,每当我尝试检查文件是否存在于其路径时,我总是会得到错误的响应。在iOS 13之前这从来不是问题,但不是我完全无法加载图像,没有错误消息。
我这样创建文件路径:
func cachePathWithName(name: String) -> String {
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
let cachesPath: String = paths as String
let cachePath = cachesPath.stringByAppendingPathComponent(path: name)
createPathIfNecessary(path: cachesPath)
createPathIfNecessary(path: cachePath)
return cachePath
}
func getFilePathForURL(url: URL, folderName: String) -> String {
return cachePathWithName(name: folderName).stringByAppendingPathComponent(path: "\(url.hashValue)")
}
let filePath = getFilePathForURL(url: url1, folderName: "TILE_CACHE")
这就是我检查文件是否存在于路径:
if file.fileExists(atPath: filePath) {
}
答案 0 :(得分:0)
尝试使用此代码
<script type="text/javascript" src="app.js?v=12392823"></script>