Compare commits

...

3 Commits

Author SHA1 Message Date
QQQ
cfaa21a860 完善方法,log 和注释。 2024-05-20 14:34:28 +08:00
QQQ
03fd39eff5 尝试另一种方式的批量下载 2024-05-17 20:02:24 +08:00
QQQ
569d0d5c02 增加读取 AccountInfo 时的判断,优化方法效率 2024-05-17 15:34:20 +08:00
8 changed files with 212 additions and 24 deletions

View File

@@ -635,6 +635,7 @@
9BFE0D8E2898C8C300F53C24 /* XPAnchorCardSkillCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE0D8D2898C8C300F53C24 /* XPAnchorCardSkillCollectionViewCell.m */; };
9BFE0D922899042600F53C24 /* XPTaskCompleteTipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE0D912899042600F53C24 /* XPTaskCompleteTipView.m */; };
9BFE992E288142FD009DA429 /* RoomClassifyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE992D288142FD009DA429 /* RoomClassifyModel.m */; };
9D63AAD32BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D63AAD22BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m */; };
E801274027E323C800BAC3F2 /* XPRoomPKViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E801273F27E323C800BAC3F2 /* XPRoomPKViewController.m */; };
E801274327E323E500BAC3F2 /* XPRoomPKPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E801274227E323E500BAC3F2 /* XPRoomPKPresenter.m */; };
E801274727E3241700BAC3F2 /* Api+RoomPK.m in Sources */ = {isa = PBXBuildFile; fileRef = E801274627E3241700BAC3F2 /* Api+RoomPK.m */; };
@@ -2773,6 +2774,8 @@
9BFE0D912899042600F53C24 /* XPTaskCompleteTipView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPTaskCompleteTipView.m; sourceTree = "<group>"; };
9BFE992C288142FD009DA429 /* RoomClassifyModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoomClassifyModel.h; sourceTree = "<group>"; };
9BFE992D288142FD009DA429 /* RoomClassifyModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoomClassifyModel.m; sourceTree = "<group>"; };
9D63AAD12BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TabbarViewController+TabbarViewController_AnimationFileCache.h"; sourceTree = "<group>"; };
9D63AAD22BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "TabbarViewController+TabbarViewController_AnimationFileCache.m"; sourceTree = "<group>"; };
B66633E061B1B34177CD011C /* Pods-YuMi.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YuMi.release.xcconfig"; path = "Target Support Files/Pods-YuMi/Pods-YuMi.release.xcconfig"; sourceTree = "<group>"; };
CACF623970097D653132D69A /* Pods_YuMi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_YuMi.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E801273E27E323C800BAC3F2 /* XPRoomPKViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomPKViewController.h; sourceTree = "<group>"; };
@@ -10093,6 +10096,8 @@
9BE01AF42893E7E000B50299 /* Cell */,
189DD53226DE255300AB55B1 /* TabbarViewController.h */,
189DD53326DE255300AB55B1 /* TabbarViewController.m */,
9D63AAD12BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.h */,
9D63AAD22BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m */,
2331C0DA2A5E9E9000E1D940 /* PIFullScreenBannerAnimation.h */,
2331C0DB2A5E9E9000E1D940 /* PIFullScreenBannerAnimation.m */,
142721B029A7647F00C7C423 /* XPBlankViewController.h */,
@@ -11726,6 +11731,7 @@
9B42869528C1E00A009034D2 /* XPRedPacketResultModel.m in Sources */,
2331C16E2A5EB71000E1D940 /* XPNobleAuthorityDescView.m in Sources */,
9BE01AE428937EDE00B50299 /* XPDressUpShopCollectionViewCell.m in Sources */,
9D63AAD32BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m in Sources */,
1427219129A75F6F00C7C423 /* MultipartMessageHeaderField.m in Sources */,
186A534B26FC6ED900D67B2C /* TTPopupManagerService.m in Sources */,
E8BD0F8B28A9EB0A00DE050D /* RoomSailingPrizeListModel.m in Sources */,

View File

@@ -0,0 +1,16 @@
//
// NSObject+TabbarViewController_AnimationFileCache.h
// YuMi
//
// Created by 123 on 2024/5/17.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSObject ()
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,18 @@
//
// TabbarViewController+TabbarViewController_AnimationFileCache.h
// YuMi
//
// Created by 123 on 2024/5/17.
//
#import "TabbarViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TabbarViewController (TabbarViewController_AnimationFileCache)
- (void)cacheAnimationResources;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,16 @@
//
// TabbarViewController+TabbarViewController_AnimationFileCache.m
// YuMi
//
// Created by 123 on 2024/5/17.
//
#import "TabbarViewController+TabbarViewController_AnimationFileCache.h"
@implementation TabbarViewController (TabbarViewController_AnimationFileCache)
- (void)cacheAnimationResources {
}
@end

View File

@@ -126,6 +126,9 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
@property(nonatomic,strong) PIFullScreenBannerAnimation *roomAnimation;
@property(nonatomic, assign) NSInteger allResourcesCount;
@property(nonatomic, assign) NSInteger downloadedResourcesCount;
@end
@implementation TabbarViewController
@@ -334,36 +337,48 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
}
///
-(void)requestGiftList{
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 开始时间:%@", [NSDate date]);
@kWeakify(self);
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
AFNetworkReachabilityManager *networkManager = [AFNetworkReachabilityManager sharedManager];
[networkManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
@kStrongify(self);
switch (status) {
case AFNetworkReachabilityStatusUnknown:
// MARK:
[[UploadFile share] pasuBatchDownload];
break;
case AFNetworkReachabilityStatusNotReachable:
// MARK:
[[UploadFile share] pasuBatchDownload];
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
{
if(self.isFirstReachability == NO){
[self dealWithDefaultSvga];
[self dealWithGiftList];
// [self dealWithDefaultSvga];
// [self removeCacheFromOldMethod];
[Api requestCacheGiftDynamicEffectList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if(code == 200){
self.isFirstReachability = YES;
NSArray *list = data.data;
NSSet *setList = [[NSSet alloc]initWithArray:list];///
for (NSString *url in setList) {
self.isFirstReachability = YES; // MARK: wifi ==
//
NSArray *allResourceList = data.data;
NSSet *allResourceSet = [[NSSet alloc] initWithArray:allResourceList];
NSMutableArray *allResourceURLs = @[].mutableCopy;
for (NSString *url in allResourceSet) {
NSString *encodingUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "].invertedSet];
[self cacheGiftDynamicEffectList:encodingUrl];
[allResourceURLs addObject:encodingUrl];
// [self cacheGiftDynamicEffectList:encodingUrl];
}
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:
@@ -371,7 +386,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
}
}];
[networkManager startMonitoring];
}
-(void)dealWithDefaultSvga{
@@ -387,7 +402,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
-(void)cacheGiftDynamicEffectList:(NSString *)url{
NSString *fileName = [[url componentsSeparatedByString:@"/"] lastObject];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) safeObjectAtIndex1:0] stringByAppendingPathComponent:@"GiftDynamicEffectList"];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) safeObjectAtIndex1:0] stringByAppendingPathComponent:@"GiftDynamicEffectList"]; // MARK: path
NSString *fullPath = [filePath stringByAppendingPathComponent:fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
return;
@@ -396,15 +411,16 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
[fileMgr createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
[UploadFile downloadAudioWithFileName:fileName musicUrl:url mainFileName:@"GiftDynamicEffectList" completion:^(BOOL isSuccess, NSString *editAudioPath) {
if(isSuccess){
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 原方法下载成功:%@, 时间:%@", editAudioPath, [NSDate date]);
}else{
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 原方法下载失败:%@", [NSDate date]);
}
self.downloadedResourcesCount+=1;
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 已处理资源资源:%ld", (long)self.downloadedResourcesCount);
}];
}
-(void)dealWithGiftList{
///
-(void)removeCacheFromOldMethod{
/// 2
NSString *svgaFileName = @"/GiftSvga";
NSString *svgaFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:svgaFileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:svgaFilePath]) {
@@ -412,7 +428,6 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
if(isSuccess == YES){
NSLog(@"删除成功");
}
}
NSString *mp4FileName = @"/GiftMp4";
@@ -422,7 +437,6 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
if(isSuccess == YES){
NSLog(@"删除成功");
}
}
}

View File

@@ -52,7 +52,15 @@ static AccountInfoStorage *_instance = nil;
if (self.accountModel != nil) {
return self.accountModel;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:[self getFilePath]] == NO) {
return nil;
}
NSData *data = [[NSData alloc] initWithContentsOfFile:[self getFilePath]];
if (data == nil) {
return nil;
}
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
//

View File

@@ -37,7 +37,13 @@ NS_ASSUME_NONNULL_BEGIN
failure:(void (^)(NSNumber *resCode, NSString *message))failure;
///下载资料
-(void)downloadAnimationFileName:(NSString *)fileName localPath:(NSString *)localPath completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion;
- (void)downloadAnimationFileName:(NSString *)fileName localPath:(NSString *)localPath completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion;
// 批量下载
- (void)startBatchDownloadWithURLs:(NSArray<NSString *> *)URLs;
- (void)pasuBatchDownload;
- (void)resumeBatchDownload;
@end
NS_ASSUME_NONNULL_END

View File

@@ -15,6 +15,12 @@ static UploadFile* manager;
//
@property (nonatomic) QCloudCredentailFenceQueue* credentialFenceQueue;
@property(nonatomic,strong) UploadFileModel *fileModel;
// MARK: object
@property (nonatomic, strong) AFHTTPSessionManager *manager;
@property (nonatomic, strong) NSData *resumeData;
@property (nonatomic, strong) NSMutableArray<NSURLSessionDownloadTask *> *tasks;
@end
@implementation UploadFile
@@ -258,7 +264,10 @@ static UploadFile* manager;
[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];
}
+(void)downloadAudioWithFileName:(NSString *)fileName musicUrl:(NSString *)musicUrl mainFileName:(NSString *)mainFileName completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion {
+(void)downloadAudioWithFileName:(NSString *)fileName
musicUrl:(NSString *)musicUrl
mainFileName:(NSString *)mainFileName
completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSURL *url = [NSURL URLWithString:[musicUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
NSURLRequest *request = [NSURLRequest requestWithURL :url];
@@ -275,4 +284,99 @@ static UploadFile* manager;
}];
[download resume];
}
//
- (void)startBatchDownloadWithURLs:(NSArray<NSString *> *)URLs {
if (_manager == nil) {
// _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];
}
if (URLs.count == 0) {
return;
}
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];
//
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *destinationURL = [documentsDirectoryURL URLByAppendingPathComponent:[url lastPathComponent]];
//
if ([[NSFileManager defaultManager] fileExistsAtPath:[destinationURL path]]) {
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 文件已存在,跳过下载: %@", destinationURL);
[filePaths addObject:destinationURL];
continue;
}
NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:request
progress:nil
destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
//
return destinationURL;
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
if (error) {
[errors addObject:error];
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 下载失败:%@, %@", error, [NSDate date]);
} else {
[filePaths addObject:filePath];
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 下载成功:%@, 时间:%@", filePath, [NSDate date]);
}
if (filePaths.count + errors.count + count == URLs.count) {
//
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 全部完成:%ld %@", (unsigned long)URLs.count, [NSDate date]);
}
}];
[self.tasks addObject:downloadTask];
}
for (NSURLSessionDownloadTask *task in self.tasks) {
[task resume];
}
}
- (void)pasuBatchDownload {
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 暂停下载");
for (NSURLSessionDownloadTask *task in self.tasks) {
[task cancelByProducingResumeData:^(NSData * _Nullable resumeData) {
if (resumeData) {
self.resumeData = resumeData;
}
}];
}
}
- (void)resumeBatchDownload {
if (self.resumeData) {
NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithResumeData:self.resumeData progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
if (error) {
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 续传下载失败: %@", error.localizedDescription);
} else {
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 续传下载文件保存到: %@", filePath);
}
}];
[downloadTask resume];
}
}
@end