[英]iOS push notifications - badges won't show
如果我收到通知,則徽章不會顯示。
我在這里注冊通知(如您所見,已選擇徽章):
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" +
" }" +
"}";
通知顯示在頂部,但應用程序圖標上沒有任何徽章。
在有效載荷中,“徽章”需要處於外部警報狀態。 例:
{"aps": {
"alert": {
"title": "title",
"body": "body"
},
"sound": "default",
"badge": 8
}
}
另外,您需要設置應用程序徽章-
UIApplication.shared.applicationIconBadgeNumber = "your badge number from response "
徽章編號為0時,此徽章將被隱藏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.