NSPOSIXErrorDomain 哪里下载文件
Posted
技术标签:
【中文标题】NSPOSIXErrorDomain 哪里下载文件【英文标题】:NSPOSIXErrorDomain wher download file 【发布时间】:2015-10-22 13:03:18 【问题描述】:我有下一个从 url 下载文件的代码。但我收到下一个错误:
失败并出现错误:错误域=NSCocoaErrorDomain 代码=516 ““CFNetworkDownload_85Dvq4.tmp”无法移动到“文档” 因为已经存在同名项目。” UserInfo=NSSourceFilePathErrorKey=/Users/otani/Library/Developer/CoreSimulator/Devices/8BABC203-7FD9-4F03-BF0D-D660DD29CCDE/data/Containers/Data/Application/09C714D3-F185-4289-91DB-13B21557B784/tmp/CFNetworkDownload_85Dvq4。温度, NSUserStringVariant=( 移动),NSDestinationFilePath=/Users/otani/Library/Developer/CoreSimulator/Devices/8BABC203-7FD9-4F03-BF0D-D660DD29CCDE/data/Containers/Data/Application/09C714D3-F185-4289-91DB-13B21557B784/Documents/temp.法尔格, NSFilePath=/Users/otani/Library/Developer/CoreSimulator/Devices/8BABC203-7FD9-4F03-BF0D-D660DD29CCDE/data/Containers/Data/Application/09C714D3-F185-4289-91DB-13B21557B784/tmp/CFNetworkDownload_85Dvq4.tmp, NSUnderlyingError=0x7fea5a53a9a0 错误域=NSPOSIXErrorDomain Code=17 "文件存在"
下载文件代码如下:
func downloadFile(let url: String!)
self.downloadHUD()
Alamofire.download(.GET, url) temporaryURL, response in
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
let fullPath = documentsUrl.URLByAppendingPathComponent(Misc.pathToSaveFile)
if (NSFileManager.defaultManager().fileExistsAtPath(fullPath.absoluteString))
try! NSFileManager.defaultManager().removeItemAtURL(fullPath)
return fullPath
.progress bytesRead, totalBytesRead, totalBytesExpectedToRead in
dispatch_async(dispatch_get_main_queue())
self.hud.progress = Float(totalBytesRead) / Float(totalBytesExpectedToRead)
print("Total bytes read on main queue: \(totalBytesRead)")
.response _, _, _, error in
if let error = error
print("Failed with error: \(error)")
else
print("Downloaded file successfully")
self.hideHUD()
错误上线
print("Failed with error: \(error)")
【问题讨论】:
【参考方案1】:解决方案是重写删除目标文件。
【讨论】:
以上是关于NSPOSIXErrorDomain 哪里下载文件的主要内容,如果未能解决你的问题,请参考以下文章
AFNetworking/NSURLConnection 接收 NSPOSIXErrorDomain Code=9 "操作无法完成。错误的文件描述符"
(错误域=NSPOSIXErrorDomain 代码=100“协议错误”
React Native 构建命令失败:PhaseScriptExecution ...(域=NSPOSIXErrorDomain,代码=2)
错误域 = NSPOSIXErrorDomain 代码 = 28 “设备上没有剩余空间” UserInfo = _kCFStreamErrorCodeKey = 28,_kCFStreamErrorD
Flutter App 无法在 IoS 模拟器上运行,运行器内有循环,并且 domain=NSPOSIXErrorDomain,code=63