如何增加重复本地通知的应用程序徽章编号(iPhone)

The*_*imp 7 iphone uilocalnotification

我已经设置了每分钟重复的本地通知,但是我需要每次都增加应用程序徽章编号.当我运行它的时候它似乎没有增加,它只是保持1.请有人帮助我吗?

以下是我创建通知的方法:

// Create the UILocalNotification
UILocalNotification *myNotification = [[UILocalNotification alloc] init];
myNotification.alertBody = @"Blah blah blah...";
myNotification.alertAction = @"Blah";
myNotification.soundName = UILocalNotificationDefaultSoundName;
myNotification.applicationIconBadgeNumber++;
myNotification.timeZone = [NSTimeZone defaultTimeZone];
myNotification.repeatInterval = NSMinuteCalendarUnit;
myNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:30];
[[UIApplication sharedApplication] scheduleLocalNotification:myNotification];
Run Code Online (Sandbox Code Playgroud)

d.e*_*nis 21

经过大量研究后,我发现解决方案是没有解决方案:

iPhone:通过本地通知增加应用程序徽章

当您的应用在后台时,无法使用本地通知动态更新徽章编号.您必须使用推送通知.

  • 虽然这个答案在技术上是正确的,但您实际上可以使用共享的UIApplication实例完成Crazy Chimp想要做的一些额外工作.每次安排新的本地通知或应用程序加载时,您都可以使用'scheduledLocalNotifications'属性和'cancelAllLocalNotifications'属性取消所有将来的通知,并通过按时间顺序枚举并递增来将徽章计数重新分配给将来的本地通知您指定的徽章编号.Def并不像输入applicationBadgeNumber ++那么容易,但它确实有效. (6认同)