Просмотр исходного кода

RA Image

增加上传任务的保存与读取
Ray Zhang 9 лет назад
Родитель
Сommit
917e032992

BIN
Ants Contract/AntsContract.xcworkspace/xcuserdata/Ray.xcuserdatad/UserInterfaceState.xcuserstate


BIN
RA Image/RA Image.xcodeproj/project.xcworkspace/xcuserdata/ray.xcuserdatad/UserInterfaceState.xcuserstate


+ 21 - 0
RA Image/RA Image/AppDelegate.m

@@ -77,6 +77,27 @@ void UncaughtExceptionHandler(NSException *exception) {
 }
 
 - (void)saveUploadTasks {
+    
+    if(true)
+    {
+        
+        if(self.uploadManager.arr_queue!=nil)
+        {
+            
+//            NSMutableArray *tmpArr = [NSMutableArray array];
+//            for (NSDictionary *dic in self.uploadManager.arr_queue) {
+//                NSMutableDictionary *mutDic = [dic mutableCopy];
+//                [mutDic removeObjectForKey:@"operation"];
+//                [mutDic removeObjectForKey:@"status"];
+//                [tmpArr addObject:mutDic];
+//            }
+            [self.uploadManager stopAllTasks];
+            [self.uploadManager saveTasks];
+
+            
+        }
+        return;
+    }
     NSString *path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_uploadTasks",self.user]];
     NSMutableArray *tmpArr = [NSMutableArray array];
     for (NSDictionary *dic in self.uploadManager.arr_queue) {

+ 6 - 0
common/upload/RAUploadManager.h

@@ -30,9 +30,15 @@
 
 @property (assign) bool removeFinish;
 @property (assign) bool removeError;
+@property (assign) bool autoStart;
+
+
 
 @property (strong,nonatomic) NSOperationQueue* operation_queue;
 
+
+-(void) stopAllTasks;
+-(void) saveTasks;
 //@property (nonatomic,weak) id <RAUploadManagerDelegate> delegate;
 
 @end

+ 46 - 1
common/upload/RAUploadManager.m

@@ -15,7 +15,8 @@
 - (instancetype)init {
     if (self = [super init]) {
         
-        self.arr_queue = [[NSMutableArray alloc] init];
+        [self loadTasks];
+
         self.newtaskStatus = TaskStatusWait;
         self.maxThread = 3;
         self.removeError=true;
@@ -121,6 +122,42 @@
     path= [path stringByAppendingPathComponent:task[@"file"]];
     return path;
 }
+-(void) saveTasks
+{
+    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    [defaults setObject:self.arr_queue forKey:@"upload_queue"];
+    [defaults synchronize];
+}
+-(void) loadTasks
+{
+    [self stopAllTasks];
+    
+    NSMutableArray* arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"upload_queue"];
+    if(arr!=nil)
+        self.arr_queue=arr;
+    else
+        self.arr_queue= [[NSMutableArray alloc] init];
+    
+    for(NSMutableDictionary* task in arr)
+    {
+        if([task[@"status"] intValue]==TaskStatusStart)
+            task[@"status"]=[NSNumber numberWithInteger:TaskStatusWait];
+        
+        if(self.autoStart)
+           [self startTask:task];
+    }
+    
+    
+}
+-(void) stopAllTasks
+{
+    for(NSMutableDictionary* task in self.arr_queue)
+    {
+        
+        [self stopTask:task];
+    }
+    
+}
 -(void) stopTask:(NSMutableDictionary*) task
 {
     
@@ -133,6 +170,14 @@
     task[@"progress"] = [NSNumber numberWithDouble:0.0];
     
     
+}
+-(void) startAllTasks
+{
+
+        
+    for(NSMutableDictionary* task in self.arr_queue)
+        [self startTask:task];
+
 }
 -(void) startTask:(NSMutableDictionary*) task
 {