当前位置:网站首页>Oc/swift Technology Download File (breakpoint continuation AFN download file alamofire Download File native download) (source code)
Oc/swift Technology Download File (breakpoint continuation AFN download file alamofire Download File native download) (source code)
2022-07-26 06:09:00 【Feng Hanxu】
I always feel that what I write is not technology , But feelings , One tutorial after another is the trace of one's own journey . Success with expertise is the most replicable , I hope my path will make you less detours , I hope I can help you erase the dust of knowledge , I hope I can help you clarify the context of knowledge , I hope there will be you and me on the top of technology in the future .
Preface
Recently downloaded to be a music player , I have a problem downloading music , Download when the network is too laggy mp3 music , On the way to download request time out. Then you can't download . I don't know how to relink and continue downloading , Use it at the beginning Alamofire The interceptor of reactivates the download , Find and download again , That's not good , The best thing is to continue downloading , Later, you can continue downloading after disconnecting the network by using breakpoint continuous transmission .
The content written below is not very perfect , But for fear of forgetting, I'd better record it first , Optimize again when free .
Before we begin , First, let's talk about how to download resources for testing , You can use Google browser , Check a downloaded resource online to download , During the download process, you can click , Look at the picture below .

In this way, the download address can be tested .
On the subject
Alamofire 5.4.4 Download the file
Alamofire Download File source code

It's OK to use this download method if the network is smooth , If the network card is downloaded, the download will fail if there is a link timeout .
Even if setting an extended timeout is useless .
AF.sessionConfiguration.timeoutIntervalForRequest = 3600
Alamofire Interceptor ( Re Download )
Later, I searched the Internet , think Alamofire The request has an interceptor , When the link fails , Interceptors can be used to intercept , Then download again .


But there will be a problem , Even if the relink succeeds, it will be downloaded again , Only the previous record of disconnecting money is gone , Need to download again , In this case , If no one disconnects while downloading , Download again , Become a dead cycle , Never download successfully .
The final solution is to continue with the breakpoint of the original sound …
Breakpoint continuation
Breakpoint continuation source code
Breakpoint continuation uses native URLSession To achieve , You can start downloading , Stop downloading , Downloading again will continue to download on the basis of the previous one . If there is an error in the download , You can save the downloaded content , Then try again and link again to continue downloading .
Let's talk about the core code :
1. If there is a problem during the download process, you can try to re link the download path to continue downloading 
2. You can stop downloading while downloading 
3. Then click the start button to continue downloading 
Use AFN Download the file
AFURLSessionManager
AFURLSessionManager Source link
use AFN Download available AFURLSessionManager Class to create objects to download .
The method of the following picture is in AFN On the basis of another layer of packaging , Then call this method from outside to directly pass URL You can download .

Use :
The following picture is the download effect. I have tried it without problem :
AFHTTPSessionManager
AFHTTPSessionManager Source code address
AFN You can also use AFHTTPSessionManager Class to create an object to download 
Use :
The following picture is the download effect. I have tried it without problem 
边栏推荐
- em和rem
- VRRP principle and basic commands
- 时序动作定位 | 用于弱监督时态动作定位的细粒度时态对比学习(CVPR 2022)
- 1.12 basis of Web Development
- Understanding the mathematical essence of machine learning
- Sequential action localization | fine grained temporal contrast learning for weak supervised temporal action localization (CVPR 2022)
- ament_cmake生成ROS2库并链接
- 【BM2 链表内指定区间反转】
- Matlab 向量与矩阵
- Qu Weihai, chairman and CEO of Xinyi interactive, adheres to mutual benefit and win-win results, and Qu Weihai promotes enterprise development
猜你喜欢

金仓数据库 KingbaseES SQL 语言参考手册 (6. 表达式)

ETCD数据库源码分析——Cluster membership changes日志

光量子里程碑:6分钟内解决3854个变量问题

Optical quantum milestone: 3854 variable problems solved in 6 minutes

日志收集分析平台搭建-1-环境准备

Docking wechat payment (II) unified order API

Matlab vector and matrix

JDBC streaming query and cursor query

Concurrency opening -- take you from 0 to 1 to build the cornerstone of concurrency knowledge system

YOLOv6:又快又准的目标检测框架开源啦
随机推荐
Operating steps for uninstalling the mobile app
Flex layout
Read five articles in the evening | Economic Daily: don't treat digital collections as wealth making products
Ganglia installation and deployment process
日志收集分析平台搭建-1-环境准备
Huawei cloud koomessage is a new marketing weapon in the hot public beta
VS中使用动态库
【Day_05 0422】连续最大和
YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
Kingbasees SQL language reference manual of Jincang database (9. Common DDL clauses)
VRRP protocol and experimental configuration
递归函数中 有两个递归入口的时间复杂度
Interview difficulties: difficulties in implementing distributed session, this is enough!
K. Link with Bracket Sequence I dp
Talking about the practice of software defect management
Properties of binary tree~
Docking wechat payment (II) unified order API
ament_cmake生成ROS2库并链接
【BM2 链表内指定区间反转】
Mysql45 talking about global lock, table lock and row lock