相关疑难解决方法(0)

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

是否可以在应用程序未运行时通过本地通知增加应用程序徽章?

我知道如何设置徽章,但没有找到任何方法来增加此值.

localNotification.applicationIconBadgeNumber = 23;

更新:我找到了一个(远非完美)解决方案.如果用户未打开应用并为每个+1事件添加通知,您可以预测会发生什么.

一个例子:

  • 第1天:计数= 0
  • 对于第2天:localNotification.applicationIconBadgeNumber = 1;
  • 对于第3天:localNotification.applicationIconBadgeNumber = 2;
  • 对于第4天:localNotification.applicationIconBadgeNumber = 3;

==>将这些通知放在一个数组中,并在应用程序退出之前设置它们.

但是,我正在寻找比此解决方案更好的解决方案.

iphone cocoa-touch push-notification ios4 uilocalnotification

28
推荐指数
3
解决办法
2万
查看次数

用户通知框架徽章不会增加

我UserNotification在我的应用程序中使用框架并发送本地通知(不是推送通知),我想将徽章设置为收到的通知数量,所以我所做的是将收到的通知数量设置为用户默认值然后我尝试将值分配给徽章以获取徽章编号,但徽章编号不会增加.这是我的代码

设置接收通知的值

center.getDeliveredNotifications { notification in

    UserDefaults.standard.set(notification.count, forKey: Constants.NOTIFICATION_COUNT)
    print("notification.count \(notification.count)")
    print(".count noti \(UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))")

}
Run Code Online (Sandbox Code Playgroud)

这准确地打印了收到的通知数量,当我决定将其设置为我的徽章时,它只显示1

content.badge = NSNumber(value: UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))
Run Code Online (Sandbox Code Playgroud)

我不知道为什么价值不会每次都增加.任何帮助,将不胜感激.

或者,如果可以随时在应用程序中的任何位置更新徽章.

ios swift usernotifications

7
推荐指数
1
解决办法
676
查看次数