在几分钟内,我同时收到了两个不同的本地通知。 但应用程序的徽章编号显示“1”而不是“2”
我的代码:
var localNotification = UILocalNotification()
localNotification.userInfo = ["UUID": FirstReminderString, ]
localNotification.fireDate = SameDay
localNotification.alertBody = "Reminder !"
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
答案 0 :(得分:1)
如果您的应用处于前台模式:您可以通过以下代码调整徽章编号:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
application.applicationIconBadgeNumber = application.applicationIconBadgeNumber + 1; // increase counter
}
如果app处于后台模式,则不会调用此方法。
所以我们必须在服务器上做一些事情如下:
func sendLocalNotif(notifCountAlreadySent:Int) {
var localNotification = UILocalNotification()
localNotification.userInfo = ["UUID": FirstReminderString, ]
localNotification.fireDate = SameDay
localNotification.alertBody = "Reminder !"
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.applicationIconBadgeNumber = notifCountAlreadySent + 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
看看它是否有帮助。此功能接收跟踪号码。这被用作徽章编号。您只需跟踪已发送的通知数量。
答案 1 :(得分:0)
当您安排通知时,将获取当前的徽章编号(并且可能为0)。因此,对于您在徽章编号递增之前安排的所有通知,新徽章编号将为1。