徽章計數未顯示在我的應用程序中用於背景和終止情況。 我的appdelegate didfinishlaunch添加該代碼徽章計數未在iOS應用程序中顯示
UIApplication.shared.applicationIconBadgeNumber = 0
if #available(iOS 10, *)
{
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
guard error == nil else
{
return
}
if granted
{
UIApplication.shared.registerForRemoteNotifications()
}
}
}
else
{
let settings : UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .sound , .badge], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
UIApplication.shared.registerForRemoteNotifications()
}
UIApplication.shared.applicationIconBadgeNumber += 1
print("Badge Count ===> \(UIApplication.shared.applicationIconBadgeNumber)")
打印顯示正確的計數。但未在應用程序中顯示。
其實我不需要更新每個通知的徽章數量。對於某些股份或類似情況,我們需要更新徽章數量。所以我創建了一個方法並更新了計數。從
請嘗試評論此行UIApplication.shared.applicationIconBadgeNumber = 0 並再次檢查 – KKRocks
請您分享您的有效負載信息。 – Nirmalsinh