// // appToTVManager.m // 隐私保护 // // Created by xd h on 2025/3/18. // #import "appToTVManager.h" @interface appToTVManager () @property(nonatomic,strong)NSMutableArray *waitingArr;//等待安装的app列表 @property (nonatomic, strong) NSArray *installingArr;//正在安装的APP列表 @property (nonatomic, assign) NSInteger installindex;//正在安装的顺序 @end @implementation appToTVManager + (instancetype)shareInstance { static appToTVManager *_instance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[self alloc] init]; }); return _instance; } - (void)addAppToTVByList:(NSArray*)list { if(!list || list.count==0){ return; } //第一次进入 安装中 待安装的都没有 if(!_installingArr && !_waitingArr){ _installingArr = [NSArray arrayWithArray:list]; _installindex = 0; [self beginToTVFun]; } else{ NSMutableArray *installList = [NSMutableArray new]; if(!_waitingArr){ _waitingArr = [NSMutableArray array]; } //排重 for (getInstalledAppModel*model in list) { BOOL canInstall = YES; for (getInstalledAppModel*waitingModel in _waitingArr) { if([model.path isEqualToString:waitingModel.path]){ canInstall = NO; break; } } if(canInstall){ for (getInstalledAppModel*installModel in _installingArr) { if([model.path isEqualToString:installModel.path]){ canInstall = NO; break; } } } if (canInstall) { [installList addObject:model]; } } [_waitingArr addObjectsFromArray:installList]; } } - (void)beginToTVFun { if (_installindex >= _installingArr.count) { _installindex = 0; if(_waitingArr.count > 0){ _installingArr = [NSArray arrayWithArray:_waitingArr]; [_waitingArr removeAllObjects]; [self beginToTVFun]; } else { _installingArr = @[]; } } else{ getInstalledAppModel*installModel = _installingArr[_installindex]; NSMutableDictionary*paraDict = [NSMutableDictionary new]; if (installModel.path) { [paraDict setObject:installModel.path forKey:@"path"]; } else{ _installindex++; [self beginToTVFun]; } KWeakSelf [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"installApkToTv" Parameters:paraDict success:^(id _Nonnull responseObject) { SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.status == 0){ } weakSelf.installindex++; [weakSelf beginToTVFun]; } failure:^(NSError * _Nonnull error) { }]; } } @end