IOS10: 未显示徽章数
IOS10: badge count not displayed
我正在使用以下代码在我的应用程序图标上显示一个数字作为徽章:
func triggerNotification(iAmountToday: Int) {
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) { (granted, error) in
if granted {
let content = UNMutableNotificationContent()
content.badge = iAmountToday
content.categoryIdentifier = "com.psv.localNotification"
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 1.0, repeats: false)
let request = UNNotificationRequest.init(identifier: "AmountTodayUpdate", content: content, trigger: trigger)
let center = UNUserNotificationCenter.currentNotificationCenter()
center.addNotificationRequest(request, withCompletionHandler: { (error) in
if (error != nil) {
print (error)
}
})
}
}
}
虽然没有抛出错误,但徽章从未显示在应用程序图标上。
我做错了什么?
干杯
Swift3.0,iOS10.
你应该替换:
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) { (granted, error) in
与:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (success, error) in
这对我有用。
此致
法比奥
我正在使用以下代码在我的应用程序图标上显示一个数字作为徽章:
func triggerNotification(iAmountToday: Int) {
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) { (granted, error) in
if granted {
let content = UNMutableNotificationContent()
content.badge = iAmountToday
content.categoryIdentifier = "com.psv.localNotification"
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 1.0, repeats: false)
let request = UNNotificationRequest.init(identifier: "AmountTodayUpdate", content: content, trigger: trigger)
let center = UNUserNotificationCenter.currentNotificationCenter()
center.addNotificationRequest(request, withCompletionHandler: { (error) in
if (error != nil) {
print (error)
}
})
}
}
}
虽然没有抛出错误,但徽章从未显示在应用程序图标上。
我做错了什么?
干杯
Swift3.0,iOS10.
你应该替换:
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) { (granted, error) in
与:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (success, error) in
这对我有用。
此致 法比奥