Commit 54a8f2fb authored by David黄金龙's avatar David黄金龙
parents 381bc32c cfd3df0b
......@@ -52,13 +52,16 @@ extension AppDelegate: JPUSHRegisterDelegate {
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
// 转换到消息tab
NotificationCenter.default.post(name: YhConstant.YhNotification.didSwithToMsgTabNotification, object: nil)
}
//后台进前台
func applicationDidEnterBackground(_ application: UIApplication) {
//销毁通知红点
UIApplication.shared.applicationIconBadgeNumber = 0
JPUSHService.setBadge(0)
// UIApplication.shared.applicationIconBadgeNumber = 0
// JPUSHService.setBadge(0)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
}
......
......@@ -20,12 +20,14 @@ class YHTabBarViewController: ESTabBarController {
super.viewDidLoad()
handleTabBarLine()
addObservers()
self.delegate = self
}
func addObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(loginSuccess), name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(logoutSuccess), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(clearAllUnreadMsg), name: YhConstant.YhNotification.didMarkAllMessagesReadedNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(switchToMsgTab), name: YhConstant.YhNotification.didSwithToMsgTabNotification, object: nil)
}
}
......@@ -48,6 +50,22 @@ extension YHTabBarViewController {
printLog("登出成功")
}
// 转换到消息tab
@objc func switchToMsgTab() {
DispatchQueue.main.async {
self.selectedIndex = 2
}
}
@objc func clearAllUnreadMsg() {
DispatchQueue.main.async {
if let vcs = self.viewControllers, let msgListVC = vcs[safe: 2] {
msgListVC.tabBarItem.badgeValue = ""
UIApplication.shared.applicationIconBadgeNumber = 0
}
}
}
func getTotalUnreadMsgCount() {
self.viewModel.requestTotalUnreadMsgCount {
[weak self] success, error in
......@@ -55,27 +73,17 @@ extension YHTabBarViewController {
DispatchQueue.main.async {
if let vcs = self.viewControllers, let msgListVC = vcs[safe: 2] {
var count = self.viewModel.unreadTotalCount
let count = self.viewModel.unreadTotalCount
var unreadText = String(count)
if count > 99 {
unreadText = "99+"
}
msgListVC.tabBarItem.badgeValue = unreadText
UIApplication.shared.applicationIconBadgeNumber = count
}
}
}
}
@objc func clearAllUnreadMsg() {
DispatchQueue.main.async {
if let vcs = self.viewControllers, let msgListVC = vcs[safe: 2] {
msgListVC.tabBarItem.badgeValue = ""
UIApplication.shared.applicationIconBadgeNumber = 0
}
}
}
}
extension YHTabBarViewController {
......@@ -94,6 +102,16 @@ extension YHTabBarViewController {
} completion: { Bool in
}
}
}
extension YHTabBarViewController: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if let vcs = self.viewControllers, let msgVC = vcs[safe: 2], viewController == msgVC {
// 点击消息tab 清空应用icon未读数
UIApplication.shared.applicationIconBadgeNumber = 8
}
}
}
......@@ -199,5 +199,8 @@ extension YhConstant {
//清空所有未读消息数
public static let didMarkAllMessagesReadedNotifiction = Notification.Name(rawValue: "com.yinhe.msgPage.readAll")
// 自动转换到消息tab
public static let didSwithToMsgTabNotification = Notification.Name(rawValue: "com.yinhe.msgPage.switch")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment