如果我收到通知,则不会显示角标(Badge)。
这是我注册通知的位置(如您所见,选择了角标(Badge)):
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if error == nil {
if granted {
print("granted")
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
UNUserNotificationCenter.current().delegate = self
}
} else {
print("not granted")
}
}
}
} else {
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [UIUserNotificationType.badge, UIUserNotificationType.sound, UIUserNotificationType.alert], categories: nil)
UIApplication.shared.registerForRemoteNotifications()
UIApplication.shared.registerUserNotificationSettings(settings)
}
这是我的有效负载:
notificationJsonPayload =
"{\"aps\" : " +
" {" +
" \"alert\": \"$(Message)\"," +
" \"badge\": 1" +
" }" +
"}";
通知显示在顶部,但应用程序图标上没有任何角标(Badge)。
最佳答案
您还需要设置应用程序角标(Badge) -
UIApplication.shared.applicationIconBadgeNumber = "your badge number from response "
当角标(Badge)编号为0时,该角标(Badge)将被隐藏。
关于iOS 推送通知 - 角标(Badge)不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49557635/