guowilling / srdownloadmanager Goto Github PK
View Code? Open in Web Editor NEWPowerful and easy-to-use file download manager based on NSURLSession. Provide download status, progress and completion callback block.
License: MIT License
Powerful and easy-to-use file download manager based on NSURLSession. Provide download status, progress and completion callback block.
License: MIT License
When I suspend all my waiting downloads suspendAllDownloads;
, then resume it resumeAllDownloads
, it loses the original order.
@guowilling 我在公司项目中使用了SRDownloadManager,感觉还是不错的,目前发现两个问题:
问题1. 下载过程中的plist写入操作崩溃:
在批量下载多个文件时,在这里会出现崩溃,原因是Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFDictionary: 0x2815d2680> was mutated while being enumerated.'
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(nonnull void (^)(NSURLSessionResponseDisposition))completionHandler {
...
// 崩溃在这里
[self.filesTotalLengthPlist writeToFile:SRFilesTotalLengthPlistPath atomically:YES];
...
}
分析原因:
下载开始时会从主线程里对这个字典进行读写操作,下载回调代理didReceiveResponse
也会对字典进行读写操作,但是发生其他线程中;而批量下载很容易导致同时在多个线程中对该字典进行读写,造成冲突。
解决方案:
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(nonnull void (^)(NSURLSessionResponseDisposition))completionHandler {
...
[self.lock1 lock];
self.filesTotalLengthPlist[SRFileName(downloadModel.URL)] = @(totalLength);
[self.filesTotalLengthPlist writeToFile:SRFilesTotalLengthPlistPath atomically:YES];
[self.lock1 unlock];
...
}
- (void)deleteDownloadedFileOfURL:(NSURL *)URL {
...
[self.lock2 lock];
[self.filesTotalLengthPlist removeObjectForKey:SRFileName(URL)];
[self.filesTotalLengthPlist writeToFile:SRFilesTotalLengthPlistPath atomically:YES];
[self.lock2 unlock];
...
}
问题2. 我们项目中使用了自己定义的下载目录,由于其他清理文件的操作导致了下载目录被删除,但是SRDownloadManager并不知情,所以下次下载文件时,总是出现file download incomplete
的问题。
分析原因:
由于下载目录的缺失,执行到[outputStream open]
会因为找不到目录而导致出错,这时候outputStream.streamError
会出现Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={_kCFStreamErrorCodeKey=2, _kCFStreamErrorDomainKey=1}
的问题
解决方案:
[outputStream open]
后,建议检查下outputSteam
的streamError
或者streamStatus
,可能这时候会有错误,需要重视[outputStream write:maxLength:]
时建议拿到方法return的数据,如果返回0
或者-1
的话,说明写入出错,需要重视[fileManager createDirectoryAtPath:]
最后我解释一下为什么自己说了这么多,确没有帮你改掉并且提交PR
呢?
正好今天是程序员节
, So thanks for open source. Wish for the best!
支持Pod,赞一个。
请问怎么获取多个任务的进度。一个课程有多个课件
可能需要一个获取单个任务大小的接口。
When download through tableview SRDownloadManager is reduce it's accuracy and downloading url in other TableView row so how can fix this, i think this library no longer maintain.
当前页面下载的时候,暂停下载,返回上一页,页面被释放,重新回到下载页面继续下载,无响应
Pod still on 1.5.0
from last year
for循环中下载,偶尔会出现这个错误,不是必现
The issues might help some people, but if they aren't in english, most of the developer can't read it easily
下载进度100%,也可以正常播放。但是状态判断有问题。
把所有的下载都暂停了, 等待一段时间, 会走代理方法 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
报错: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x610000054cd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://yxfile.idealsee.com/9f6f64aca98f90b91d260555d3b41b97_mp4.mp4, NSErrorFailingURLKey=http://yxfile.idealsee.com/9f6f64aca98f90b91d260555d3b41b97_mp4.mp4, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}
如何获取所有加入下载的数据源(失败,正在下载,完成,暂停,取消),我想要通过这个单例获取数据源给tableView的列表.需要对里面那个模型进行数据库保存吗
Would be really good if I could prioritize a URL, then it should be the first to pick (even on FIFO or FILO)
Use case: I'm downloading a lot of videos, but i want to download the video I need first, even if the URL is in the middle of waiting array
Hi my use case is like this
I start a download and show a status of that download in that page, now I go back to my home page and there I want to show the download status of that particular element. The main approach is to get the download progress of the file by its unique identifier. Do you have that kind of thing?
我用Xcode自带的内存工具检测,检测到下载的时候存在leaks。
希望可以支持cocoapods集成
我测试的时候发现了些问题,表示很不解:
1、APP在下载过程中突然崩溃了,如何去保存completionHandler()?
2、在- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler 中,好像并不需要创建参照? 我发现没创建也是OK的,不知道和创建了有什么区别
3、如果我创建了多个NSURLSession,到后台后是不是要保存多份completionHandler()?
4、我重新进入APP的时候,创建NSURLSession就自动给我继续下载了,导致我在逻辑处理出了问题,怎么让它不自动下载?
Can you please add the background download facility
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.