私はユーザー通知を設定しました。彼らはうまくいきますが、アプリアイコンのバッジは常に1つです。ここ は私のコードです:Swift UNUnnnnnn通知アプリケーションIconBadgeNumberは常に1を表示します
let center = UNUserNotificationCenter.current()
let options: UNAuthorizationOptions = [.alert, .badge, .sound];
center.requestAuthorization(options: options) {
(granted, error) in
if !granted {
// ask for permission
}
}
使用は、私がNOTIFをスケジュールボタンをクリックすると:
@IBAction func saveBtnPressed(sender: UIButton) {
scheduleNotif()
}
ここscheduleNotif機能は
func scheduleNotif() {
let dateformatter = DateFormatter()
dateformatter.dateStyle = DateFormatter.Style.medium
dateformatter.timeStyle = DateFormatter.Style.short
let dateFromString = dateformatter.date(from: selectDateTextField.text!)
let fireDateOfNotification: Date = dateFromString!
//Notif are enabled
let content = UNMutableNotificationContent()
content.title = notifTitleTextField.text!
content.body = notifNoteTextView.text
content.sound = UNNotificationSound.default()
content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber
var trigger: UNCalendarNotificationTrigger
var triggerDate = DateComponents()
trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: false)
let titleNospace = notifTitleTextField.text?.replacingOccurrences(of: " ", with: "")
var identifier = titleNospace
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
self.center.add(request, withCompletionHandler: { (error) in
if let error = error {
print(error.localizedDescription)
}
})
}
さんのバッジは常に1が表示されますなぜすべてのアイデアを通知が配信されると増分しませんか?
は、私はあなたがapplicationIconBadgeNumber
をインクリメントする必要があると思うあなた
:だからでは
を交換してください。アップルはローカル通知のバッジ自動増分を提供していません。 – Mannopson
@Mannopsonなので、基本的に、通知が届いたときにそのラベルを増やす方法はありませんか? – Marco
ただし、正しい値を指定してバッジとして設定することができます。例: 'content.badge = deliveredNotifications.count'またはそのようなもの(届かなかった通知の数だけを表示) – Mannopson