// // NSURLSession+customDownloadTask.m // Private-X // // Created by xd h on 2024/7/1. // #import "NSURLSession+customDownloadTask.h" @implementation NSURLSession (customDownloadTask) - (NSURLSessionDataTask *)custom_downloadDataTaskWithURLString:(NSString *)urlString startSize:(int64_t)startSize { // 校验URL if (urlString.length == 0) { return nil; } NSURL *url = [NSURL URLWithString:urlString]; if (url == nil) { return nil; } // 创建请求 设置请求下载的位置 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; //NSString *tokenStr = [[UseAccountManage shareInstance] cloudAutoh]; //[request setValue:tokenStr forHTTPHeaderField:@"Authorization"]; request.HTTPMethod = @"GET"; /* bytes=0-100 请求0-100 bytes=200-1000 bytes=200- 从200开始直到结尾 bytes=-100 */ NSString *rangeStr = [NSString stringWithFormat:@"bytes=%lld-",startSize]; [request setValue:rangeStr forHTTPHeaderField:@"Range"]; // 创建task return [self dataTaskWithRequest:request]; } @end