浏览代码

ensure UIApplication.shared.applicationIconBadgeNumber will be called from the main thread

cyberta 4 年之前
父节点
当前提交
d4a10f324d
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      deltachat-ios/Helper/NotificationManager.swift

+ 7 - 5
deltachat-ios/Helper/NotificationManager.swift

@@ -10,11 +10,13 @@ public class NotificationManager {
 
 
 
 
     public static func updateApplicationIconBadge(reset: Bool) {
     public static func updateApplicationIconBadge(reset: Bool) {
-        if reset {
-            UIApplication.shared.applicationIconBadgeNumber = 0
-        } else {
-            let array = DcContext.shared.getFreshMessages()
-            UIApplication.shared.applicationIconBadgeNumber = array.count
+        var unreadMessages = 0
+        if !reset {
+            unreadMessages = DcContext.shared.getFreshMessages().count
+        }
+
+        DispatchQueue.main.async {
+            UIApplication.shared.applicationIconBadgeNumber = unreadMessages
         }
         }
     }
     }