关于AFUrlSessionManager下载文件报The file couldn’t be opened because the specified URL type isn’t support问题
来源:互联网 发布:网络事件 2017 编辑:程序博客网 时间:2024/06/05 16:21
今天遇到一个问题,就是用AFUrlSessionManager下载文件的时候,下载过程中一切正常,但是去解压这个文件的时候,却发现该文件不存在,找了半天还以为是路径有问题,确定了很多遍发现路径没有问题,最后一点点跟代码才发现问题原因,这里记录一下。
AFUrlSessionManager下载文件的流程是先将文件下载到一个临时文件夹下面,然后移动到指定的目录下面并重新命名,问题就是发生在这里,打断点发现是移动.tmp文件的时候出错了,移动文件的代码如下:
if (self.downloadTaskDidFinishDownloading) { self.downloadFileURL = self.downloadTaskDidFinishDownloading(session, downloadTask, location); if (self.downloadFileURL) { [[NSFileManager defaultManager] moveItemAtURL:location toURL:self.downloadFileURL error:&fileManagerError]; NSLog(@"fileManagerError=%@",fileManagerError); if (fileManagerError) { [[NSNotificationCenter defaultCenter] postNotificationName:AFURLSessionDownloadTaskDidFailToMoveFileNotification object:downloadTask userInfo:fileManagerError.userInfo]; } } }
错误信息如下:
The file couldn’t be opened because the specified URL type isn’t supported.
最后发现,这个NSFileManager读取本地文件的时候,必须加上file://这个url头,不然就会报这个错,我这里的两个参数location和self.downloadFileURL前者有加这个头,后者是自己定义的沙盒路径没有加这个,所以移动文件的时候会报错,使用[NSURL fileURLWithPath:filePath]返回的就是加上了file://头的本地路径了。
另外需要注意的是,如果目标路径下存在了名称一样的文件,是移不过去的,需要先将同名文件删除,再移动。
阅读全文
0 0
- 关于AFUrlSessionManager下载文件报The file couldn’t be opened because the specified URL type isn’t support问题
- Info.plist文件报错,The data couldn’t be read because it isn’t in the correct format.
- iOS运行报错:the file couldn't be opened because you don't have permission to view it 。
- IOS开发报错-The file “XXXX” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- The file “***” couldn’t be opened because you don’t have permission to view it
- 解决方案:The file * couldn't be opened because you don't have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- the file couldn't be opened because you don't have permission to view it
- the file couldn't be opened because you don't have permission to view it 解决办法
- The file “xxx” couldn’t be opened because you don’t have permission to view it.
- 薪水涨幅查询
- 数据库视频总结
- N
- UE4 连接自定义服务器
- Flume+Kafka环境构建和实战
- 关于AFUrlSessionManager下载文件报The file couldn’t be opened because the specified URL type isn’t support问题
- Android 性能优化:使用 Lint 优化代码、去除多余资源
- 实训第八天
- maven 阿里下载源 setting.xml
- CSS——important和盒模型
- JavaScript基础之浏览器对象
- 获取url里面的参数,并转化为json
- 解释型语言与编译型语言有什么不同
- 题目236:心急的C小加