Commit 12b54065 authored by Steven杜宇's avatar Steven杜宇

// 消息

parent 2d9667bd
......@@ -62,11 +62,11 @@ extension AppDelegate: JPUSHRegisterDelegate {
}
//后台进前台
func applicationDidEnterBackground(_ application: UIApplication) {
//销毁通知红点
// UIApplication.shared.applicationIconBadgeNumber = 0
// JPUSHService.setBadge(0)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
func applicationWillEnterForeground(_ application: UIApplication) {
DispatchQueue.main.async {
// 请求消息页面通知权限通知
NotificationCenter.default.post(name: YhConstant.YhNotification.didReqeustNotifyPermissionNotification, object: nil)
}
}
func jpushNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: ((Int) -> Void)) {
......
......@@ -37,6 +37,10 @@ class YHMessageDetailListVC: YHBaseViewController {
[weak self] in
guard let self = self else { return }
YHCommonAlertView.show("清除未读", "确定要清除所有未读提示吗?", "取消", "确认") {
if self.msgArr.count <= 0 {
YHHUD.flash(message: "暂无消息~")
return
}
self.markAllMsgsRead()
}
}
......
......@@ -15,11 +15,11 @@ class YHMessageListVC: YHBaseViewController {
let model = YHMsgViewModel()
return model
}()
var isNotifyEnabled = false
lazy var tableView: UITableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
tableView.sectionHeaderHeight = 42.0
tableView.estimatedSectionHeaderHeight = 1.0
tableView.estimatedSectionFooterHeight = 1.0
tableView.showsVerticalScrollIndicator = false
tableView.separatorStyle = .none
......@@ -49,6 +49,10 @@ class YHMessageListVC: YHBaseViewController {
bar.rightBtnClick = {
[weak self] in
guard let self = self else { return }
if self.msgArr.count <= 0 {
YHHUD.flash(message: "暂无消息~")
return
}
YHCommonAlertView.show("清除未读", "确定要清除所有未读提示吗?", "取消", "确认") {
self.markAllMsgsRead()
}
......@@ -92,12 +96,13 @@ class YHMessageListVC: YHBaseViewController {
super.viewWillAppear(animated)
YHLoginManager.shared.needJumpToMsgTabFlag = false
getUnreadMsgList()
checkNotificationPermisson()
NotificationCenter.default.post(name: YhConstant.YhNotification.didRequestUnreadMsgTotalCountNotification, object: nil)
}
func setupUI() {
addObservers()
gk_navigationBar.isHidden = true
view.backgroundColor = .white
view.addSubview(navBar)
......@@ -112,16 +117,22 @@ class YHMessageListVC: YHBaseViewController {
make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalToSuperview().offset(-k_Height_TabBar)
}
}
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(getUnreadMsgList), name: YhConstant.YhNotification.didRequestUnreadMsgListNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(getUnreadMsgList), name: YhConstant.YhNotification.didRequestUnreadMsgListNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(checkNotificationPermisson), name: YhConstant.YhNotification.didReqeustNotifyPermissionNotification, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
@objc func loginSuccess() {
printLog("登录成功,进行相应的 UI刷新操作")
}
@objc func logoutSuccess() {
......@@ -183,6 +194,42 @@ class YHMessageListVC: YHBaseViewController {
}
}
}
@objc func checkNotificationPermisson() {
checkNotificationAuthorizationStatus {
[weak self] granted in
guard let self = self else { return }
DispatchQueue.main.async {
self.isNotifyEnabled = granted
self.tableView.reloadData()
}
}
}
func checkNotificationAuthorizationStatus(_ callBack:((Bool)->())?) {
UNUserNotificationCenter.current().getNotificationSettings { settings in
var enableStatus = false
switch settings.authorizationStatus {
case .authorized:
print("通知已授权")
enableStatus = true
case .denied:
print("通知被拒绝")
enableStatus = false
case .notDetermined:
print("通知权限尚未确定")
enableStatus = false
case .provisional:
print("通知以临时方式授权")
enableStatus = false
case .ephemeral:
enableStatus = false
@unknown default:
break
}
callBack?(enableStatus)
}
}
}
extension YHMessageListVC {
......@@ -203,6 +250,10 @@ extension YHMessageListVC {
extension YHMessageListVC: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return msgArr.count
}
......@@ -233,7 +284,10 @@ extension YHMessageListVC: UITableViewDelegate, UITableViewDataSource {
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
return 42.0
if !isNotifyEnabled {
return 42.0
}
return 1.0
}
private func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> CGFloat {
......@@ -247,6 +301,10 @@ extension YHMessageListVC: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if isNotifyEnabled {
return UIView()
}
let view = UIView()
view.backgroundColor = UIColor(hex: 0x3570DC, alpha: 0.06)
......@@ -270,10 +328,11 @@ extension YHMessageListVC: UITableViewDelegate, UITableViewDataSource {
make.right.equalTo(enableBtn.snp.left).offset(-20)
make.centerY.equalToSuperview()
}
enableBtn.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: 26, height: 18))
make.size.equalTo(CGSize(width: 26, height: 42.0))
make.right.equalToSuperview().offset(-20)
make.centerY.equalToSuperview()
make.top.bottom.equalToSuperview()
}
return view
}
......
......@@ -32,6 +32,22 @@ class YHMyNotifySettingVC: YHBaseViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
checkNotifyPermission()
}
func setupUI() {
gk_navTitle = "通知设置".local
view.backgroundColor = .white
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalToSuperview().offset(-k_Height_TabBar)
}
NotificationCenter.default.addObserver(self, selector: #selector(checkNotifyPermission), name: YhConstant.YhNotification.didReqeustNotifyPermissionNotification, object: nil)
}
@objc func checkNotifyPermission() {
checkNotificationAuthorizationStatus {
[weak self] granted in
guard let self = self else { return }
......@@ -46,17 +62,6 @@ class YHMyNotifySettingVC: YHBaseViewController {
}
}
func setupUI() {
gk_navTitle = "通知设置".local
view.backgroundColor = .white
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalToSuperview().offset(-k_Height_TabBar)
}
}
func checkNotificationAuthorizationStatus(_ callBack:((Bool)->())?) {
UNUserNotificationCenter.current().getNotificationSettings { settings in
var enableStatus = false
......
......@@ -137,6 +137,10 @@ class YHMyPermissionSettingVC: YHBaseViewController {
completion(false)
}
}
deinit {
NotificationCenter.default.removeObserver(self)
}
}
extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource {
......
......@@ -205,5 +205,8 @@ extension YhConstant {
// 请求消息未读列表通知
public static let didRequestUnreadMsgListNotification = Notification.Name(rawValue: "com.yinhe.msgPage.unreadList")
// 请求通知权限通知
public static let didReqeustNotifyPermissionNotification = Notification.Name(rawValue: "com.yinhe.msgPage.notifyPermission")
}
}
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