我正在寻找一个中心,每天为徽章图标添加1。我尝试了多种方法,但没有更新图标徽章编号。
override func viewDidLoad() {
super.viewDidLoad()
let localNotification:UILocalNotification = UILocalNotification()
localNotification.fireDate = datePicker.date
localNotification.alertBody = nil;
localNotification.alertAction = nil;
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.repeatInterval = NSCalendarUnit.Day
//Add one to the icon badge number
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1;
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
答案 0 :(得分:0)
所以我会选择另一种方法。我的想法是设置一个自动重复计时器,每隔86,400(24小时/ 1天)启动并发送通知。如果可行,徽章计数将自动增加一个。
//!pseudo-code!
let timer = NSTimer.scheduledTimerWithTimeInterval(864000, target: self, selector: "sendNotification:", userInfo: nil, repeats: true)
func sendNotification(timer: NSTimer) {
//initialize and send your notification w/ repeatCount: 0 and fireDate: now
//hide the banner so the user does not visually see the notification if you wish
}
我不确定如果应用程序没有运行,这是否会起作用,但可能值得一试。