在Swift中关闭应用程序时,徽章图标未更新

时间:2018-06-24 13:51:15

标签: ios swift notifications badge

我使用以下代码在图标上显示当天的日期,但是除非输入应用程序,否则第二天的日期不会更新:

let date = NSDate()
let calender = NSCalendar(calendarIdentifier: NSCalendar.Identifier.persian)
let components = calender?.components(NSCalendar.Unit(rawValue: UInt.max), from: date as Date)
let day = components!.day
let badgeCount: Int = day!
let application = UIApplication.shared
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in }
application.registerForRemoteNotifications()
application.applicationIconBadgeNumber = badgeCount

0 个答案:

没有答案