ASI的request:didReceiveData:下载后,没有数据
在iOS开发过程中,使用ASI进行数据的下载,在使用协议方法request:didReceiveData:显示下载百分比的时候,会导致程序运行完成后,数据丢失。我在网上查资料,有个网友说:“request:didReceiveData:不能用于文件的下载,只能用于地址解析等情况”。
我在request:didReceiveData:解释中发现了这么一段话:
// When a delegate implements this method, it is expected to process all incoming data itself
// This means that responseData / responseString / downloadDestinationPath etc are ignored
// You can have the request call a different method by setting didReceiveDataSelector
这段话的大体意思就是这个方法会把传输的数据保存,原数据都会被忽视。可以通过其他的一个方法进行实现。经过网上的查资料以及和小伙伴们的讨论,总结出了两个解决方法。
解决方法:
1.使用request:didReceiveBytes:方法,此方法和request:didReceiveData:不同。它需要使用代理[Request setDownloadProgressDelegate:self];[Request setAllowResumeForFileDownloads:YES];
2.使用setBytesReceivedBlock:^(unsigned long long size, unsigned long long total)方法。推荐使用这个方法,效率更高。
如果有什么不对的地方,还请大神补充。
4 评论
谢了,我就说没有保存到指定的位置,原来是实现了这个代理方法就默认不保存了,哈哈
作为一个站长,我却看不懂这是什么东西
分享您的想法?
撰写评论