appToTVManager.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // appToTVManager.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2025/3/18.
  6. //
  7. #import "appToTVManager.h"
  8. @interface appToTVManager ()
  9. {
  10. NSTimer *CheckSecondTimer; //
  11. }
  12. @property(nonatomic,strong)NSMutableArray *waitingArr;//等待安装的app列表
  13. @property (nonatomic, strong) NSArray *installingArr;//正在安装的APP列表
  14. @property (nonatomic, assign) NSInteger installindex;//正在安装的顺序
  15. @end
  16. @implementation appToTVManager
  17. + (instancetype)shareInstance {
  18. static appToTVManager *_instance;
  19. static dispatch_once_t onceToken;
  20. dispatch_once(&onceToken, ^{
  21. _instance = [[self alloc] init];
  22. });
  23. return _instance;
  24. }
  25. - (void)addAppToTVByList:(NSArray*)list
  26. {
  27. if(!list || list.count==0){
  28. return;
  29. }
  30. //第一次进入 安装中 待安装的都没有
  31. if(!_installingArr && !_waitingArr){
  32. _installingArr = [NSArray arrayWithArray:list];
  33. _installindex = 0;
  34. [self beginToTVFun];
  35. }
  36. else{
  37. NSMutableArray *installList = [NSMutableArray new];
  38. if(!_waitingArr){
  39. _waitingArr = [NSMutableArray array];
  40. }
  41. //排重
  42. for (getInstalledAppModel*model in list) {
  43. BOOL canInstall = YES;
  44. for (getInstalledAppModel*waitingModel in _waitingArr) {
  45. if([model.path isEqualToString:waitingModel.path]){
  46. canInstall = NO;
  47. break;
  48. }
  49. }
  50. if(canInstall){
  51. for (getInstalledAppModel*installModel in _installingArr) {
  52. if([model.path isEqualToString:installModel.path]){
  53. canInstall = NO;
  54. break;
  55. }
  56. }
  57. }
  58. if (canInstall) {
  59. [installList addObject:model];
  60. }
  61. }
  62. [_waitingArr addObjectsFromArray:installList];
  63. }
  64. if (CheckSecondTimer) {
  65. [CheckSecondTimer invalidate];
  66. }
  67. // CheckSecondTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  68. // [[NSRunLoop currentRunLoop] addTimer:CheckSecondTimer forMode:NSRunLoopCommonModes];
  69. }
  70. - (void)timerChange{
  71. // if (_installindex < _installingArr.count) {
  72. //
  73. // }
  74. }
  75. - (void)beginToTVFun
  76. {
  77. if (_installindex >= _installingArr.count) {
  78. _installindex = 0;
  79. if(_waitingArr.count > 0){
  80. _installingArr = [NSArray arrayWithArray:_waitingArr];
  81. [_waitingArr removeAllObjects];
  82. [self beginToTVFun];
  83. }
  84. else {
  85. _installingArr = @[];
  86. if (CheckSecondTimer) {
  87. [CheckSecondTimer invalidate];
  88. }
  89. }
  90. }
  91. else{
  92. getInstalledAppModel*installModel = _installingArr[_installindex];
  93. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  94. if (installModel.path) {
  95. [paraDict setObject:installModel.path forKey:@"path"];
  96. }
  97. else{
  98. _installindex++;
  99. [self beginToTVFun];
  100. }
  101. KWeakSelf
  102. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"installApkToTv" Parameters:paraDict success:^(id _Nonnull responseObject) {
  103. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  104. if(model && model.status == 0){
  105. }
  106. weakSelf.installindex++;
  107. [weakSelf beginToTVFun];
  108. } failure:^(NSError * _Nonnull error) {
  109. weakSelf.installindex++;
  110. [weakSelf beginToTVFun];
  111. }];
  112. }
  113. }
  114. @end