1.缓存优化,bug修复

This commit is contained in:
liyuhua
2024-05-17 16:57:28 +08:00
parent 82a476fd46
commit 2c3c6ad17d
15 changed files with 141 additions and 84 deletions

View File

@@ -275,4 +275,50 @@ static UploadFile* manager;
}];
[download resume];
}
+(void)downloadGiftDynamicEffectWithList:(NSSet *)list completion:(void (^) (BOOL isSuccess, NSMutableArray *editAudioPath))completion{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.operationQueue.maxConcurrentOperationCount = 20; //
dispatch_group_t requestGroup = dispatch_group_create();
NSMutableArray *failList = [NSMutableArray array];
for (NSString *giftUrl in list) {
NSString *encodingUrl = [giftUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "].invertedSet];
NSString *fileName = [[encodingUrl componentsSeparatedByString:@"/"] lastObject];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) safeObjectAtIndex1:0] stringByAppendingPathComponent:@"GiftDynamicEffectList"];
NSString *fullPath = [filePath stringByAppendingPathComponent:fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
continue;
}
NSFileManager *fileMgr = [[NSFileManager alloc] init];
[fileMgr createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
dispatch_group_enter(requestGroup);
NSURL *url = [NSURL URLWithString:[encodingUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
NSURLRequest *request = [NSURLRequest requestWithURL :url];
NSURLSessionDownloadTask *download = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
return [NSURL fileURLWithPath:fullPath];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
dispatch_group_leave(requestGroup);
if (!error) {
NSLog(@"下载完成");
} else {
NSLog(@"下载失败");
[failList addObject:encodingUrl];
}
}];
[download resume];
}
dispatch_group_notify(requestGroup, dispatch_get_main_queue(), ^{
if(failList.count > 0){
completion(NO,failList);
NSLog(@"下载有失败");
}else{
NSLog(@"下载全部完成");
completion(NO,nil);
}
});
}
@end