/// 重设App图标未读数
///
/// - Returns: 当前未读数
class func resetAppIconBageNumber() -> Int {
let sysNum = UserDefaults.standard.integer(forKey: SystemUnNotice)
let orderNum = UserDefaults.standard.integer(forKey: OrderUnNotice)
let assignOrderNum = UserDefaults.standard.integer(forKey: AssignOrderNotice)
let privateNum = SNIMManager.getAllSessionAllUnReadNumber()
let num:Int = sysNum + orderNum + assignOrderNum + privateNum
if num == 0 {
if #available(iOS 11.0, *){//-1 仅让appIcon消失 不让push消失 仅11有用 10以下用下种方法
UIApplication.shared.applicationIconBadgeNumber = -1
}else{ //会触发"didReceive notification: UILocalNotification"方法
let clearEpisodeNotification:UILocalNotification = UILocalNotification.init()
clearEpisodeNotification.applicationIconBadgeNumber = UIApplication.shared.applicationIconBadgeNumber
UIApplication.shared.scheduleLocalNotification(clearEpisodeNotification)
clearEpisodeNotification.applicationIconBadgeNumber = -1
UIApplication.shared.scheduleLocalNotification(clearEpisodeNotification)
}
}else{
UIApplication.shared.applicationIconBadgeNumber = num
}
return num
}
注意:这个方法不能在 application(_ application: UIApplication, didReceive notification: UILocalNotification) 方法中调用哦!!!