Compare commits
3 Commits
12c76609c5
...
feature/1.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cfaa21a860 | ||
![]() |
03fd39eff5 | ||
![]() |
569d0d5c02 |
@@ -635,6 +635,7 @@
|
|||||||
9BFE0D8E2898C8C300F53C24 /* XPAnchorCardSkillCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE0D8D2898C8C300F53C24 /* XPAnchorCardSkillCollectionViewCell.m */; };
|
9BFE0D8E2898C8C300F53C24 /* XPAnchorCardSkillCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE0D8D2898C8C300F53C24 /* XPAnchorCardSkillCollectionViewCell.m */; };
|
||||||
9BFE0D922899042600F53C24 /* XPTaskCompleteTipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE0D912899042600F53C24 /* XPTaskCompleteTipView.m */; };
|
9BFE0D922899042600F53C24 /* XPTaskCompleteTipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE0D912899042600F53C24 /* XPTaskCompleteTipView.m */; };
|
||||||
9BFE992E288142FD009DA429 /* RoomClassifyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BFE992D288142FD009DA429 /* RoomClassifyModel.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 */; };
|
E801274027E323C800BAC3F2 /* XPRoomPKViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E801273F27E323C800BAC3F2 /* XPRoomPKViewController.m */; };
|
||||||
E801274327E323E500BAC3F2 /* XPRoomPKPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E801274227E323E500BAC3F2 /* XPRoomPKPresenter.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 */; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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; };
|
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>"; };
|
E801273E27E323C800BAC3F2 /* XPRoomPKViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomPKViewController.h; sourceTree = "<group>"; };
|
||||||
@@ -10093,6 +10096,8 @@
|
|||||||
9BE01AF42893E7E000B50299 /* Cell */,
|
9BE01AF42893E7E000B50299 /* Cell */,
|
||||||
189DD53226DE255300AB55B1 /* TabbarViewController.h */,
|
189DD53226DE255300AB55B1 /* TabbarViewController.h */,
|
||||||
189DD53326DE255300AB55B1 /* TabbarViewController.m */,
|
189DD53326DE255300AB55B1 /* TabbarViewController.m */,
|
||||||
|
9D63AAD12BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.h */,
|
||||||
|
9D63AAD22BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m */,
|
||||||
2331C0DA2A5E9E9000E1D940 /* PIFullScreenBannerAnimation.h */,
|
2331C0DA2A5E9E9000E1D940 /* PIFullScreenBannerAnimation.h */,
|
||||||
2331C0DB2A5E9E9000E1D940 /* PIFullScreenBannerAnimation.m */,
|
2331C0DB2A5E9E9000E1D940 /* PIFullScreenBannerAnimation.m */,
|
||||||
142721B029A7647F00C7C423 /* XPBlankViewController.h */,
|
142721B029A7647F00C7C423 /* XPBlankViewController.h */,
|
||||||
@@ -11726,6 +11731,7 @@
|
|||||||
9B42869528C1E00A009034D2 /* XPRedPacketResultModel.m in Sources */,
|
9B42869528C1E00A009034D2 /* XPRedPacketResultModel.m in Sources */,
|
||||||
2331C16E2A5EB71000E1D940 /* XPNobleAuthorityDescView.m in Sources */,
|
2331C16E2A5EB71000E1D940 /* XPNobleAuthorityDescView.m in Sources */,
|
||||||
9BE01AE428937EDE00B50299 /* XPDressUpShopCollectionViewCell.m in Sources */,
|
9BE01AE428937EDE00B50299 /* XPDressUpShopCollectionViewCell.m in Sources */,
|
||||||
|
9D63AAD32BF74E82004EFB3B /* TabbarViewController+TabbarViewController_AnimationFileCache.m in Sources */,
|
||||||
1427219129A75F6F00C7C423 /* MultipartMessageHeaderField.m in Sources */,
|
1427219129A75F6F00C7C423 /* MultipartMessageHeaderField.m in Sources */,
|
||||||
186A534B26FC6ED900D67B2C /* TTPopupManagerService.m in Sources */,
|
186A534B26FC6ED900D67B2C /* TTPopupManagerService.m in Sources */,
|
||||||
E8BD0F8B28A9EB0A00DE050D /* RoomSailingPrizeListModel.m in Sources */,
|
E8BD0F8B28A9EB0A00DE050D /* RoomSailingPrizeListModel.m in Sources */,
|
||||||
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -126,6 +126,9 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
@property(nonatomic,strong) PIFullScreenBannerAnimation *roomAnimation;
|
@property(nonatomic,strong) PIFullScreenBannerAnimation *roomAnimation;
|
||||||
|
|
||||||
|
|
||||||
|
@property(nonatomic, assign) NSInteger allResourcesCount;
|
||||||
|
@property(nonatomic, assign) NSInteger downloadedResourcesCount;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation TabbarViewController
|
@implementation TabbarViewController
|
||||||
@@ -334,36 +337,48 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
}
|
}
|
||||||
///缓存礼物特效
|
///缓存礼物特效
|
||||||
-(void)requestGiftList{
|
-(void)requestGiftList{
|
||||||
|
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 开始时间:%@", [NSDate date]);
|
||||||
@kWeakify(self);
|
@kWeakify(self);
|
||||||
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
AFNetworkReachabilityManager *networkManager = [AFNetworkReachabilityManager sharedManager];
|
||||||
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
[networkManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||||
@kStrongify(self);
|
@kStrongify(self);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case AFNetworkReachabilityStatusUnknown:
|
case AFNetworkReachabilityStatusUnknown:
|
||||||
|
// MARK: 未验证
|
||||||
|
[[UploadFile share] pasuBatchDownload];
|
||||||
break;
|
break;
|
||||||
case AFNetworkReachabilityStatusNotReachable:
|
case AFNetworkReachabilityStatusNotReachable:
|
||||||
|
// MARK: 未验证
|
||||||
|
[[UploadFile share] pasuBatchDownload];
|
||||||
break;
|
break;
|
||||||
case AFNetworkReachabilityStatusReachableViaWWAN:
|
case AFNetworkReachabilityStatusReachableViaWWAN:
|
||||||
case AFNetworkReachabilityStatusReachableViaWiFi:
|
case AFNetworkReachabilityStatusReachableViaWiFi:
|
||||||
{
|
{
|
||||||
if(self.isFirstReachability == NO){
|
if(self.isFirstReachability == NO){
|
||||||
[self dealWithDefaultSvga];
|
// [self dealWithDefaultSvga];
|
||||||
[self dealWithGiftList];
|
// [self removeCacheFromOldMethod];
|
||||||
[Api requestCacheGiftDynamicEffectList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
[Api requestCacheGiftDynamicEffectList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||||
if(code == 200){
|
if(code == 200){
|
||||||
self.isFirstReachability = YES;
|
self.isFirstReachability = YES; // MARK: 只在第一次有 wifi 情况进入下载,其实后续变化也没有影响 =。=
|
||||||
NSArray *list = data.data;
|
// 这个参数命名不好,应该反映的状态是“每次启动,只触发一次缓存处理方法”
|
||||||
NSSet *setList = [[NSSet alloc]initWithArray:list];///去重,防止有重复的
|
NSArray *allResourceList = data.data;
|
||||||
for (NSString *url in setList) {
|
NSSet *allResourceSet = [[NSSet alloc] initWithArray:allResourceList];
|
||||||
|
NSMutableArray *allResourceURLs = @[].mutableCopy;
|
||||||
|
for (NSString *url in allResourceSet) {
|
||||||
NSString *encodingUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "].invertedSet];
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -371,7 +386,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
[networkManager startMonitoring];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)dealWithDefaultSvga{
|
-(void)dealWithDefaultSvga{
|
||||||
@@ -387,7 +402,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
-(void)cacheGiftDynamicEffectList:(NSString *)url{
|
-(void)cacheGiftDynamicEffectList:(NSString *)url{
|
||||||
|
|
||||||
NSString *fileName = [[url componentsSeparatedByString:@"/"] lastObject];
|
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];
|
NSString *fullPath = [filePath stringByAppendingPathComponent:fileName];
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
|
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
|
||||||
return;
|
return;
|
||||||
@@ -396,15 +411,16 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
[fileMgr createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
|
[fileMgr createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
|
||||||
[UploadFile downloadAudioWithFileName:fileName musicUrl:url mainFileName:@"GiftDynamicEffectList" completion:^(BOOL isSuccess, NSString *editAudioPath) {
|
[UploadFile downloadAudioWithFileName:fileName musicUrl:url mainFileName:@"GiftDynamicEffectList" completion:^(BOOL isSuccess, NSString *editAudioPath) {
|
||||||
if(isSuccess){
|
if(isSuccess){
|
||||||
|
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 原方法下载成功:%@, 时间:%@", editAudioPath, [NSDate date]);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
NSLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 原方法下载失败:%@", [NSDate date]);
|
||||||
}
|
}
|
||||||
|
self.downloadedResourcesCount+=1;
|
||||||
|
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 已处理资源资源:%ld", (long)self.downloadedResourcesCount);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
-(void)dealWithGiftList{
|
-(void)removeCacheFromOldMethod{
|
||||||
///删除旧数据缓存,
|
///删除旧数据缓存,预计 2 个版本后可以删除此方法
|
||||||
NSString *svgaFileName = @"/GiftSvga";
|
NSString *svgaFileName = @"/GiftSvga";
|
||||||
NSString *svgaFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:svgaFileName];
|
NSString *svgaFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:svgaFileName];
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:svgaFilePath]) {
|
if ([[NSFileManager defaultManager] fileExistsAtPath:svgaFilePath]) {
|
||||||
@@ -412,7 +428,6 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
if(isSuccess == YES){
|
if(isSuccess == YES){
|
||||||
NSLog(@"删除成功");
|
NSLog(@"删除成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *mp4FileName = @"/GiftMp4";
|
NSString *mp4FileName = @"/GiftMp4";
|
||||||
@@ -422,7 +437,6 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|||||||
if(isSuccess == YES){
|
if(isSuccess == YES){
|
||||||
NSLog(@"删除成功");
|
NSLog(@"删除成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,7 +52,15 @@ static AccountInfoStorage *_instance = nil;
|
|||||||
if (self.accountModel != nil) {
|
if (self.accountModel != nil) {
|
||||||
return self.accountModel;
|
return self.accountModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([[NSFileManager defaultManager] fileExistsAtPath:[self getFilePath]] == NO) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
NSData *data = [[NSData alloc] initWithContentsOfFile:[self getFilePath]];
|
NSData *data = [[NSData alloc] initWithContentsOfFile:[self getFilePath]];
|
||||||
|
if (data == nil) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
|
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
|
||||||
//解档出数据模型
|
//解档出数据模型
|
||||||
|
@@ -38,6 +38,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
///下载资料
|
///下载资料
|
||||||
- (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
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@@ -15,6 +15,12 @@ static UploadFile* manager;
|
|||||||
// 一个脚手架实例
|
// 一个脚手架实例
|
||||||
@property (nonatomic) QCloudCredentailFenceQueue* credentialFenceQueue;
|
@property (nonatomic) QCloudCredentailFenceQueue* credentialFenceQueue;
|
||||||
@property(nonatomic,strong) UploadFileModel *fileModel;
|
@property(nonatomic,strong) UploadFileModel *fileModel;
|
||||||
|
|
||||||
|
// MARK: 批量下载部分, 后续要新建一个 object 来承载业务
|
||||||
|
@property (nonatomic, strong) AFHTTPSessionManager *manager;
|
||||||
|
@property (nonatomic, strong) NSData *resumeData;
|
||||||
|
@property (nonatomic, strong) NSMutableArray<NSURLSessionDownloadTask *> *tasks;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation UploadFile
|
@implementation UploadFile
|
||||||
@@ -258,7 +264,10 @@ static UploadFile* manager;
|
|||||||
[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];
|
[[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];
|
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
||||||
NSURL *url = [NSURL URLWithString:[musicUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
|
NSURL *url = [NSURL URLWithString:[musicUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL :url];
|
NSURLRequest *request = [NSURLRequest requestWithURL :url];
|
||||||
@@ -275,4 +284,99 @@ static UploadFile* manager;
|
|||||||
}];
|
}];
|
||||||
[download resume];
|
[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
|
@end
|
||||||
|
Reference in New Issue
Block a user