【问题标题】:App icon badge not showing when notification arrives通知到达时未显示应用程序图标徽章
【发布时间】:2020-08-13 02:46:11
【问题描述】:

我在 iPad 上有一个应用程序。当通知来或服务器静态发送时,它不会在应用程序图标上显示徽章。我已经注册了带有徽章选项的通知,但徽章仍然没有出现在应用程序图标上。此外,当我检查设置 -> 通知 -> 我的应用程序时。它没有显示徽章的切换。只显示警报和声音,没有徽章。在这里,我在通知中附上了设置的图片。

链接:[https://prnt.sc/s7rnj0]

我的代码如下:

链接:[https://prnt.sc/s7sp9u]

从 didFinishLaunchingWithOptions 调用它

【问题讨论】:

  • 请问您是如何使用 firebase 或其他方式在您的应用中实现通知的??
  • 不使用firebase,使用UNUserNotification
  • 好吧,你可以参考这个:stackoverflow.com/a/40634374/10584330

标签: ios objective-c swift push-notification badge


【解决方案1】:
func registerForPushNotifications() {
    if #available(iOS 10.0, *) {
               let center  = UNUserNotificationCenter.current()
               let content = UNMutableNotificationContent()
                content.sound = UNNotificationSound.default
               center.delegate = self
                UNUserNotificationCenter.current().delegate = self
                center.requestAuthorization(options: [.sound, .alert, .badge]) 
     { (granted, error) in
                   if error == nil{
                       DispatchQueue.main.async {
                           UIApplication.shared.registerForRemoteNotifications()
                       }
                   }
               }

           } else {

               let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
               UIApplication.shared.registerUserNotificationSettings(settings)
               UIApplication.shared.registerForRemoteNotifications()
           }
}

//在应用委托中注册didFinishLaunchingWithOption方法的推送通知方法调用。在 ipad snap 下方。

【讨论】:

    猜你喜欢
    • 2013-02-01
    • 2014-07-18
    • 2021-07-17
    • 2017-03-08
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    相关资源
    最近更新 更多