Browse Source

improved updateApplicationIconBadgeNumber

Marino Faggiana 6 years ago
parent
commit
cafa6b14eb
2 changed files with 26 additions and 19 deletions
  1. 25 19
      iOSClient/AppDelegate.m
  2. 1 0
      iOSClient/Main/NCMainCommon.swift

+ 25 - 19
iOSClient/AppDelegate.m

@@ -777,27 +777,33 @@
     if (self.maintenanceMode)
         return;
     
-    NSInteger counterDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status = %d OR status == %d OR status == %d)", self.activeAccount, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading] sorted:@"fileName" ascending:true] count];
-    NSInteger counterUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d OR status == %d)", self.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusInUpload, k_metadataStatusUploading] sorted:@"fileName" ascending:true] count];
-
-    NSInteger total = counterDownload + counterUpload;
-    
-    [UIApplication sharedApplication].applicationIconBadgeNumber = total;
-    
-    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
-    
-    if ([[splitViewController.viewControllers firstObject] isKindOfClass:[UITabBarController class]]) {
-        
-        UITabBarController *tbc = [splitViewController.viewControllers firstObject];
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
-        UITabBarItem *tbItem = [tbc.tabBar.items objectAtIndex:0];
+        NSInteger counterDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status = %d OR status == %d OR status == %d)", self.activeAccount, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading] sorted:@"fileName" ascending:true] count];
+        NSInteger counterUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d OR status == %d)", self.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusInUpload, k_metadataStatusUploading] sorted:@"fileName" ascending:true] count];
+
+        NSInteger total = counterDownload + counterUpload;
         
-        if (total > 0) {
-            [tbItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
-        } else {
-            [tbItem setBadgeValue:nil];
-        }
-    }
+        dispatch_async(dispatch_get_main_queue(), ^{
+            
+            [UIApplication sharedApplication].applicationIconBadgeNumber = total;
+            
+            UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
+            
+            if ([[splitViewController.viewControllers firstObject] isKindOfClass:[UITabBarController class]]) {
+                
+                UITabBarController *tbc = [splitViewController.viewControllers firstObject];
+                
+                UITabBarItem *tbItem = [tbc.tabBar.items objectAtIndex:0];
+                
+                if (total > 0) {
+                    [tbItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
+                } else {
+                    [tbItem setBadgeValue:nil];
+                }
+            }
+        });
+    });
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 0
iOSClient/Main/NCMainCommon.swift

@@ -1037,6 +1037,7 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
             
             // Synchronized
             if selector == selectorDownloadSynchronize {
+                appDelegate.updateApplicationIconBadgeNumber()
                 return
             }