【发布时间】:2016-10-21 07:52:45
【问题描述】:
我正在使用以下代码在我的应用图标上显示一个数字作为徽章:
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)
}
})
}
}
}
虽然没有抛出错误,但应用程序图标上永远不会显示徽章。
我做错了什么?
干杯
【问题讨论】:
-
试试这个。 content.badge = iAmountToday 作为 NSNumber?还要检查 iAmountToday 是否有价值。
-
嗨@Wolverine,我试过这个但没有效果。 iAmountToday 至少为 0 - 我也检查过
-
尝试将其设置为至少 1
-
不,没有帮助! :-(
标签: ios swift notifications badge