我在" DidfininshLaunchingWithOptions"下添加了这段代码。希望每天更改徽章图标编号的Appedelegate。任何人都知道如何重写这个以实际工作?
let timer = NSTimer.scheduledTimerWithTimeInterval(864000, target: self, selector: "sendNotification:", userInfo: nil, repeats: true)
func sendNotification(timer: NSTimer) {
let localNotification:UILocalNotification = UILocalNotification()
localNotification.fireDate = NSDate(timeIntervalSinceNow: 3)
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 + 7
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
//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
}
答案 0 :(得分:0)
您可以在iOS中更改两个默认徽章(除了创建自定义徽章)。
UIApplication.sharedApplication().applicationIconBadgeNumber = count
self.viewController.tabBarItem.badgeValue = NSString(format: "%d", count) as String
在这两种情况下,count
都属于Int
类型。显然,第二个语句的第一部分将更改为适应您的选项卡/导航UIBarButtonItem结构。
这有帮助吗?