Browse Source

1.同步最近文件闪退问题

huangxiaodong 1 month ago
parent
commit
0c2175b8ce
1 changed files with 48 additions and 43 deletions
  1. 48 43
      创维盒子/双子星云手机/NAS/recenFile/lastFileManager.m

+ 48 - 43
创维盒子/双子星云手机/NAS/recenFile/lastFileManager.m

@@ -1,8 +1,8 @@
 //
 //  lastFileManager.m
+//  
 //
-//
-//  Created by David on 2024/6/19.
+//  Created by xd h on 2024/6/19.
 //
 
 #import "lastFileManager.h"
@@ -38,7 +38,7 @@
 //    if(!_uid || _uid.length == 0){
 //        return @"userName";
 //    }
-//    
+//
 //    return _uid;
 //}
 
@@ -71,59 +71,64 @@
 
 #pragma mark- last file  plist
 - (NSMutableDictionary *)lastFileList {
-    
-    if (!_lastFileList) { // 内存没有
-        _lastFileList = [[NSDictionary dictionaryWithContentsOfFile:[self getLastFilePlistPath]] mutableCopy]; // 本地加载
-        if (!_lastFileList) { // 本地没有,分配内存
-            _lastFileList = [NSMutableDictionary dictionary];
+    @synchronized (self) {
+        if (!_lastFileList) { // 内存没有
+            _lastFileList = [[NSDictionary dictionaryWithContentsOfFile:[self getLastFilePlistPath]] mutableCopy]; // 本地加载
+            if (!_lastFileList) { // 本地没有,分配内存
+                _lastFileList = [NSMutableDictionary dictionary];
+            }
         }
+        return _lastFileList;
     }
-    return _lastFileList;
 }
 
 
 - (NSMutableArray*)lastFileListArr{
-    if (!_lastFileListArr) { // 内存没有
-        NSMutableArray *dataArr = [NSMutableArray new];
-        if (self.lastFileList) {
-
-            for (NSString *key in self.lastFileList) {
-                NSDictionary *dict = self.lastFileList[key];
+    @synchronized (self) {
+        if (!_lastFileListArr) { // 内存没有
+            NSMutableArray *dataArr = [NSMutableArray new];
+            if (self.lastFileList) {
                 
-                lastFileModel *model = [lastFileModel mj_objectWithKeyValues:dict];
-                if(model){
-                    NSTimeInterval preTime = model.lastPreTime;
-                    if (![self areTimes:preTime MoreThanDays:self.saveDays]) {
-                        [dataArr addObject:model];
-                    }
-                    else{
-                        [self.lastFileList removeObjectForKey:key];
+                NSDictionary *preLastFileList = [NSDictionary dictionaryWithDictionary:self.lastFileList];
+                for (NSString *key in preLastFileList) {
+                    NSDictionary *dict = preLastFileList[key];
+                    
+                    lastFileModel *model = [lastFileModel mj_objectWithKeyValues:dict];
+                    if(model){
+                        NSTimeInterval preTime = model.lastPreTime;
+                        if (![self areTimes:preTime MoreThanDays:self.saveDays]) {
+                            [dataArr addObject:model];
+                        }
+                        else{
+                            [self.lastFileList removeObjectForKey:key];
+                        }
                     }
                 }
             }
-        }
-        
-        if(dataArr.count > 0){//排序
-            NSArray *sortArr = [dataArr sortedArrayUsingComparator:^NSComparisonResult(lastFileModel* obj1, lastFileModel* obj2) {
-                       NSTimeInterval time1 = obj1.lastPreTime;
-                        NSTimeInterval time2 = obj2.lastPreTime;
-                       if (time1 < time2) {
-                           return NSOrderedDescending;
-                       }
-                       if (time1 > time2) {
-                           return NSOrderedAscending;
-                       }
-                       return NSOrderedSame;
-                   }];
             
-            _lastFileListArr = [NSMutableArray arrayWithArray:sortArr];
-        }
-        else{
-            _lastFileListArr = [NSMutableArray new];
+            if(dataArr.count > 0){//排序
+                NSArray *sortArr = [dataArr sortedArrayUsingComparator:^NSComparisonResult(lastFileModel* obj1, lastFileModel* obj2) {
+                           NSTimeInterval time1 = obj1.lastPreTime;
+                            NSTimeInterval time2 = obj2.lastPreTime;
+                           if (time1 < time2) {
+                               return NSOrderedDescending;
+                           }
+                           if (time1 > time2) {
+                               return NSOrderedAscending;
+                           }
+                           return NSOrderedSame;
+                       }];
+                
+                _lastFileListArr = [NSMutableArray arrayWithArray:sortArr];
+            }
+            else{
+                _lastFileListArr = [NSMutableArray new];
+            }
+            
         }
-        
+        return _lastFileListArr;
     }
-    return _lastFileListArr;
+   
 }
 
 /**  增加配置信息 */