gpt4 book ai didi

swift - 徽章图标未更新

转载 作者:行者123 更新时间:2023-11-30 13:49:42 25 4
gpt4 key购买 nike

我在 Appedelegate 的“DidfininshLaunchingWithOptions”下添加了此代码,希望它每天都能更改徽章图标编号。有人知道我如何重写它才能真正起作用吗?

 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
}

最佳答案

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

  1. 用户主屏幕上应用图标上的徽章:

UIApplication.sharedApplication().applicationIconBadgeNumber = 计数

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

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

    这有帮助吗?

    关于swift - 徽章图标未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34441216/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com