浏览代码

clear code

marinofaggiana 4 年之前
父节点
当前提交
b4981640f2
共有 2 个文件被更改,包括 20 次插入14 次删除
  1. 1 14
      iOSClient/AppDelegate.m
  2. 19 0
      iOSClient/Main/NCMainTabBar.swift

+ 1 - 14
iOSClient/AppDelegate.m

@@ -681,22 +681,9 @@
 
 - (void)updateApplicationIconBadgeNumber
 {
-    if (self.account.length == 0) { return; }
-            
-    NSInteger counterDownload = [[NCOperationQueue shared] downloadCount];
-    NSInteger counterUpload = [[NCManageDatabase shared] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"status == %d OR status == %d OR status == %d", NCBrandGlobal.shared.metadataStatusWaitUpload, NCBrandGlobal.shared.metadataStatusInUpload, NCBrandGlobal.shared.metadataStatusUploading]].count;
-    NSInteger total = counterDownload + counterUpload;
-    
-    [UIApplication sharedApplication].applicationIconBadgeNumber = total;
-    
     UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
     if ([tabBarController isKindOfClass:[UITabBarController class]]) {
-        UITabBarItem *tabBarItem = [tabBarController.tabBar.items objectAtIndex:0];
-        if (total > 0) {
-            [tabBarItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
-        } else {
-            [tabBarItem setBadgeValue:nil];
-        }
+        [(NCMainTabBar *)tabBarController.tabBar updateBadgeNumber];
     }
 }
 

+ 19 - 0
iOSClient/Main/NCMainTabBar.swift

@@ -213,5 +213,24 @@ class NCMainTabBar: UITabBar {
             appDelegate.showMenuIn(viewController: viewController)
         }
     }
+    
+    @objc func updateBadgeNumber() {
+        
+        if appDelegate.account == nil || appDelegate.account.count == 0 { return }
+        
+        let counterDownload = NCOperationQueue.shared.downloadCount()
+        let counterUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d OR status == %d", NCBrandGlobal.shared.metadataStatusWaitUpload, NCBrandGlobal.shared.metadataStatusInUpload, NCBrandGlobal.shared.metadataStatusUploading)).count
+        let total = counterDownload + counterUpload
+        
+        UIApplication.shared.applicationIconBadgeNumber = total
+        
+        if let item = items?[0] {
+            if total > 0 {
+                item.badgeValue = String(total)
+            } else {
+                item.badgeValue = nil
+            }
+        }
+    }
 }