【发布时间】:2019-03-20 18:49:06
【问题描述】:
我正在使用以下条件,它不会对图像执行(但对视频执行)。
if let imgUrl = info[UIImagePickerControllerReferenceURL] as? URL{
let imgName = imgUrl.lastPathComponent
let documentDirectory = NSTemporaryDirectory()
let localPath = documentDirectory.appending(imgName)
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let data = UIImageJPEGRepresentation(image, 0.3)! as NSData
//data.write(toFile: localPath, atomically: true)
let photoURL = URL.init(fileURLWithPath: localPath)
let attr: NSDictionary = try! FileManager.default.attributesOfItem(atPath: (photoURL.path)) as NSDictionary
print("file size is :", attr.fileSize(), attr.fileSize()/1024, (attr.fileSize()/1024)/1024)
print(photoURL)
}
我收到错误:
线程 1:致命错误:“尝试!”表达式意外引发错误: 错误域=NSCocoaErrorDomain 代码=260 "文件“asset.JPG” 无法打开,因为没有这样的文件。” UserInfo={NSFilePath=/Users/engineering07/Library/Developer/CoreSimulator/Devices/5B35C341-204E-43F0-A2DE-199757E38835/data/Containers/Data/Application/43182136-8C82-4385-99A7-F0F30B30A785/tmp/asset. JPG, NSUnderlyingError=0x608000246360 {错误域=NSPOSIXErrorDomain Code=2 "没有这样的文件或目录"}}
我无法理解这里有什么问题或这里缺少什么。请帮助我了解如何纠正它。谢谢。
【问题讨论】: