Marino Faggiana 6 years ago
parent
commit
2a39757421
1 changed files with 27 additions and 2 deletions
  1. 27 2
      iOSClient/AppDelegate.m

+ 27 - 2
iOSClient/AppDelegate.m

@@ -1493,8 +1493,33 @@
         }
     }
     
-    // Verify Downloading
-    NSArray *recordsInDownloading = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND status == %d", self.activeAccount, k_metadataStatusDownloading] sorted:@"fileName" ascending:true];
+    // Verify Downloading 
+    NSArray *recordsInDownloading = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session != %@ AND status == %d", self.activeAccount, k_download_session_extension, k_metadataStatusDownloading] sorted:@"fileName" ascending:true];
+    for (tableMetadata *metadata in recordsInDownloading) {
+        
+        NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
+        
+        [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
+            
+            NSURLSessionTask *findTask;
+
+            for (NSURLSessionTask *task in downloadTasks)
+                if (task.taskIdentifier == metadata.sessionTaskIdentifier) {
+                    findTask = task;
+                }
+            
+            if (!findTask) {
+                
+                metadata.session = @"";
+                metadata.sessionError = @"";
+                metadata.sessionSelector = @"";
+                metadata.sessionTaskIdentifier = k_taskIdentifierDone;
+                metadata.status = k_metadataStatusNormal;
+                
+                (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
+            }
+        }];
+    }