完善方法,log 和注释。
This commit is contained in:
@@ -344,9 +344,11 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
@kStrongify(self);
|
||||
switch (status) {
|
||||
case AFNetworkReachabilityStatusUnknown:
|
||||
// MARK: 未验证
|
||||
[[UploadFile share] pasuBatchDownload];
|
||||
break;
|
||||
case AFNetworkReachabilityStatusNotReachable:
|
||||
// MARK: 未验证
|
||||
[[UploadFile share] pasuBatchDownload];
|
||||
break;
|
||||
case AFNetworkReachabilityStatusReachableViaWWAN:
|
||||
@@ -358,7 +360,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
[Api requestCacheGiftDynamicEffectList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
if(code == 200){
|
||||
self.isFirstReachability = YES; // MARK: 只在第一次有 wifi 情况进入下载,其实后续变化也没有影响 =。=
|
||||
// 所以用 Monitor 也没有太大必要 -> 修改为真正的批量下载方法
|
||||
// 这个参数命名不好,应该反映的状态是“每次启动,只触发一次缓存处理方法”
|
||||
NSArray *allResourceList = data.data;
|
||||
NSSet *allResourceSet = [[NSSet alloc] initWithArray:allResourceList];
|
||||
NSMutableArray *allResourceURLs = @[].mutableCopy;
|
||||
@@ -367,12 +369,16 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
[allResourceURLs addObject:encodingUrl];
|
||||
// [self cacheGiftDynamicEffectList:encodingUrl];
|
||||
}
|
||||
[[UploadFile share] startBatchDownloadWithURLs:allResourceURLs];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[[UploadFile share] startBatchDownloadWithURLs:allResourceURLs];
|
||||
});
|
||||
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 资源总数:%ld", (unsigned long)allResourceURLs.count);
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
// MARK: 未验证
|
||||
[[UploadFile share] resumeBatchDownload];
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@@ -288,7 +288,14 @@ static UploadFile* manager;
|
||||
// 批量下载
|
||||
- (void)startBatchDownloadWithURLs:(NSArray<NSString *> *)URLs {
|
||||
if (_manager == nil) {
|
||||
_manager = [AFHTTPSessionManager manager];
|
||||
// _manager = [AFHTTPSessionManager manager];
|
||||
|
||||
// MARK: 切换线程的思路正确,那么,整个 APP 那么多 API 没有使用异步。。。。
|
||||
// 失败数量第一次就是对的
|
||||
// 周一再测试是否外部异步,内部指定并发就可以
|
||||
// 没有指定并发数,可以下载到一半
|
||||
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.example.app.background"];
|
||||
_manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];
|
||||
_manager.operationQueue.maxConcurrentOperationCount = 10;
|
||||
_tasks = [NSMutableArray array];
|
||||
}
|
||||
@@ -300,6 +307,8 @@ static UploadFile* manager;
|
||||
NSMutableArray<NSError *> *errors = [NSMutableArray array];
|
||||
NSMutableArray<NSURL *> *filePaths = [NSMutableArray array];
|
||||
|
||||
NSInteger count = 0;
|
||||
|
||||
for (NSString *urlStr in URLs) {
|
||||
NSURL *url = [NSURL URLWithString:urlStr];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:url];
|
||||
@@ -310,9 +319,9 @@ static UploadFile* manager;
|
||||
|
||||
// 检查文件是否已经存在
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:[destinationURL path]]) {
|
||||
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 文件已存在,跳过下载: %@", destinationURL);
|
||||
[filePaths addObject:destinationURL];
|
||||
continue;
|
||||
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 文件已存在,跳过下载: %@", destinationURL);
|
||||
[filePaths addObject:destinationURL];
|
||||
continue;
|
||||
}
|
||||
|
||||
NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:request
|
||||
@@ -328,9 +337,9 @@ static UploadFile* manager;
|
||||
[filePaths addObject:filePath];
|
||||
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 下载成功:%@, 时间:%@", filePath, [NSDate date]);
|
||||
}
|
||||
if (filePaths.count + errors.count == URLs.count) {
|
||||
if (filePaths.count + errors.count + count == URLs.count) {
|
||||
// 全部任务处理完成
|
||||
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 资源总数:%ld, %@", (unsigned long)URLs.count, [NSDate date]);
|
||||
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 全部完成:%ld, %@", (unsigned long)URLs.count, [NSDate date]);
|
||||
}
|
||||
}];
|
||||
|
||||
|
Reference in New Issue
Block a user