浏览代码

Merge pull request #1122 from deltachat/applicationIconBadgeNumber_mainthread

call ApplicationIconBadgeNumber from mainthread
bjoern 4 年之前
父节点
当前提交
083126f2aa
共有 1 个文件被更改,包括 7 次插入7 次删除
  1. 7 7
      deltachat-ios/Helper/NotificationManager.swift

+ 7 - 7
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
         }
         }
     }
     }
 
 
@@ -39,8 +41,6 @@ public class NotificationManager {
                         return
                         return
                     }
                     }
 
 
-                    let array = DcContext.shared.getFreshMessages()
-                    UIApplication.shared.applicationIconBadgeNumber = array.count
                     NotificationManager.updateApplicationIconBadge(reset: false)
                     NotificationManager.updateApplicationIconBadge(reset: false)
 
 
                     let chat = DcContext.shared.getChat(chatId: chatId)
                     let chat = DcContext.shared.getChat(chatId: chatId)