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
這就是我目前使用的,然而問題是,爲什麼新框架根本不工作?它確實發送通知絕對好,但慘不忍睹的徽章管理。這是一個錯誤還是我做錯了代碼? –