iOS 重设App图标未读数

    /// 重设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) 方法中调用哦!!!

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知...
    莫离_焱阅读 11,609评论 1 8
  • 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
    欧辰_OSR阅读 30,002评论 8 265
  • 推送通知 注意:这里说的推送通知跟NSNotification有所区别 NSNotification是抽象的,不可...
    iOS开发攻城狮阅读 9,781评论 1 13
  • 极光推送: 1.JPush当前版本是1.8.2,其SDK的开发除了正常的功能完善和扩展外也紧随苹果官方的步伐,SD...
    Isspace阅读 11,722评论 10 16
  • 您曾否问过自己:“为什么想学英语”?是想认识不同的人?是想无阻碍地周游列国?还是看到别人会说一口流利标准的口...
    fionababy阅读 3,573评论 0 0

友情链接更多精彩内容