徽章图标未更新

时间:2015-12-23 17:55:09

标签: swift uilocalnotification

我在" 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
    }

1 个答案:

答案 0 :(得分:0)

您可以在iOS中更改两个默认徽章(除了创建自定义徽章)。

  1. 用户主屏幕上应用图标上的徽章:
  2. UIApplication.sharedApplication().applicationIconBadgeNumber = count

    1. UIBarButtonItem上的徽章,如标签栏或导航栏项目:
    2. self.viewController.tabBarItem.badgeValue = NSString(format: "%d", count) as String

      在这两种情况下,count都属于Int类型。显然,第二个语句的第一部分将更改为适应您的选项卡/导航UIBarButtonItem结构。

      这有帮助吗?

相关问题