let content = UNMutableNotificationContent()
content.badge = 0 // your badge count
此代码是在applicationWillEnterForeground
和目的是通过数设为0文擦除徽章用户再次进入该应用然而,已经证明完全无用的,因为它不更新应用程序图标上的徽章...的Xcode夫特3.0通知框架应用徽章不更新
我现在已经恢复到iOS 9的代码,它的工作就像一个魅力。此外,它似乎是,使用新的框架,你必须真正发出通知要更新的徽章数量这实在是不切实际的..有人请纠正我,如果我错了
此外:
let content = UNMutableNotificationContent()
TableViewController.numberBadges += 1
content.title = "Title"
content.body = "this is the body ..."
content.badge = TableViewController.numberBadges as NSNumber?
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let requestidentifier = "myNotification"
let request = UNNotificationRequest(identifier: requestidentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: {error in
// handle error if there is one
if((error) != nil){
print("Error completing notification scheduling: \(error)")
}else{
print("Added Notification request successfully with \(content.badge!) badges")
}
})
不更新徽章,所以给了什么?
你有没有试过'[UIApplication sharedApplication] .applicationIconBadgeNumber = 0;'? – deadbeef
对不起,我的意思是'UIApplication.shared.applicationIconBadgeNumber = 0' – deadbeef
这就是我目前使用的,然而问题是,为什么新框架根本不工作?它确实发送通知绝对好,但惨不忍睹的徽章管理。这是一个错误还是我做错了代码? –