Commit cb195814624b196213db570c77412bd695247a85
Merge branch 'master' of http://bj.gitlab.cnlive.com/ios-team/CNLiveMateCode
Showing
3 changed files
with
39 additions
and
24 deletions
metaCode/Classes/Config/CNLiveConfigManager.swift
| @@ -55,4 +55,14 @@ extension Notification.Name { | @@ -55,4 +55,14 @@ extension Notification.Name { | ||
| 55 | //认证身份失败通知 | 55 | //认证身份失败通知 |
| 56 | public static let StandAuthNotificationUnSuccess = Notification.Name("StandAuthNotificationUnSuccess") | 56 | public static let StandAuthNotificationUnSuccess = Notification.Name("StandAuthNotificationUnSuccess") |
| 57 | } | 57 | } |
| 58 | + struct NetworkStatus { | ||
| 59 | + //无网状态通知 | ||
| 60 | + public static let CNLiveNetworkStatusNotificationNotReachable = Notification.Name("CNLiveNetworkStatusNotificationNotReachable") | ||
| 61 | + //网络未知状态通知 | ||
| 62 | + public static let CNLiveNetworkStatusNotificationUnknown = Notification.Name("CNLiveNetworkStatusNotificationUnknown") | ||
| 63 | + //蜂窝数据状态通知 | ||
| 64 | + public static let CNLiveNetworkStatusNotificationReachableViaWWAN = Notification.Name("CNLiveNetworkStatusNotificationReachableViaWWAN") | ||
| 65 | + //WIFI状态通知 | ||
| 66 | + public static let CNLiveNetworkStatusNotificationReachableViaWiFi = Notification.Name("CNLiveNetworkStatusNotificationReachableViaWiFi") | ||
| 67 | + } | ||
| 58 | } | 68 | } |
metaCode/Classes/Main/HomePage/Controller/CNMetaCodeHomePageController.swift
| @@ -184,10 +184,11 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel | @@ -184,10 +184,11 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel | ||
| 184 | 184 | ||
| 185 | self.setupUI() | 185 | self.setupUI() |
| 186 | 186 | ||
| 187 | - /// 通知名 | ||
| 188 | - let notificationName = "CNLiveNetworkStatusNotification" | ||
| 189 | - /// 自定义通知 | ||
| 190 | - NotificationCenter.default.addObserver(self, selector: #selector(networkStatusNotificationAction), name: NSNotification.Name(rawValue: notificationName), object: nil) | 187 | + /// 网络通知 |
| 188 | + NotificationCenter.default.addObserver(self, selector: #selector(networkStatusNotificationActionNotReachable), name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationNotReachable, object: nil) | ||
| 189 | + NotificationCenter.default.addObserver(self, selector: #selector(networkStatusNotificationActionUnknown), name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationUnknown, object: nil) | ||
| 190 | + NotificationCenter.default.addObserver(self, selector: #selector(networkStatusNotificationActionReachableViaWWAN), name:Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWWAN, object: nil) | ||
| 191 | + NotificationCenter.default.addObserver(self, selector: #selector(networkStatusNotificationActionReachableViaWiFi), name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWiFi, object: nil) | ||
| 191 | 192 | ||
| 192 | // self.tabBarController?.tabBar.top = self.tabBarY + KSreenHeight | 193 | // self.tabBarController?.tabBar.top = self.tabBarY + KSreenHeight |
| 193 | 194 | ||
| @@ -233,23 +234,27 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel | @@ -233,23 +234,27 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel | ||
| 233 | } | 234 | } |
| 234 | 235 | ||
| 235 | // MARK: -事件 | 236 | // MARK: -事件 |
| 237 | + | ||
| 236 | //无网时刷新 | 238 | //无网时刷新 |
| 237 | @objc func errorFreshButtonAction(){ | 239 | @objc func errorFreshButtonAction(){ |
| 238 | self.getUserIdentityApi() | 240 | self.getUserIdentityApi() |
| 239 | } | 241 | } |
| 240 | - /// 接受到通知后的方法回调 | ||
| 241 | - @objc private func networkStatusNotificationAction(noti: Notification) { | ||
| 242 | - let netStatus:String = noti.object as! String | ||
| 243 | - switch netStatus { | ||
| 244 | -// case "notReachable"://暂时不处理 | ||
| 245 | - | ||
| 246 | - case "reachableViaWWAN": | ||
| 247 | - self.getUserIdentityApi() | ||
| 248 | - case "reachableViaWiFi": | ||
| 249 | - self.getUserIdentityApi() | ||
| 250 | - default: | ||
| 251 | - break | ||
| 252 | - } | 242 | + |
| 243 | + /// 网络变为无网 | ||
| 244 | + @objc func networkStatusNotificationActionNotReachable(){ | ||
| 245 | + print("11") | ||
| 246 | + } | ||
| 247 | + /// 网络变为未知 | ||
| 248 | + @objc func networkStatusNotificationActionUnknown(){ | ||
| 249 | + print("11") | ||
| 250 | + } | ||
| 251 | + /// 网络变为蜂窝 | ||
| 252 | + @objc func networkStatusNotificationActionReachableViaWWAN(){ | ||
| 253 | + self.getUserIdentityApi() | ||
| 254 | + } | ||
| 255 | + /// 网络变为WIFI | ||
| 256 | + @objc func networkStatusNotificationActionReachableViaWiFi(){ | ||
| 257 | + self.getUserIdentityApi() | ||
| 253 | } | 258 | } |
| 254 | 259 | ||
| 255 | // MARK: -添加约束 | 260 | // MARK: -添加约束 |
metaCode/Classes/Other/AppDelegate.swift
| @@ -19,17 +19,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | @@ -19,17 +19,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | ||
| 19 | // Override point for customization after application launch. | 19 | // Override point for customization after application launch. |
| 20 | CNLiveNetworking.networkStatus { status in | 20 | CNLiveNetworking.networkStatus { status in |
| 21 | 21 | ||
| 22 | - if(status == .notReachable || status == .unknown){ | ||
| 23 | - /// 发送简单数据 | ||
| 24 | - NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "CNLiveNetworkStatusNotification"), object: "notReachable") | 22 | + if(status == .notReachable){ |
| 23 | + NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationNotReachable, object: nil) | ||
| 24 | + } | ||
| 25 | + if(status == .unknown){ | ||
| 26 | + NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationUnknown, object: nil) | ||
| 25 | } | 27 | } |
| 26 | if status == .reachableViaWWAN { | 28 | if status == .reachableViaWWAN { |
| 27 | - /// 发送简单数据 | ||
| 28 | - NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "CNLiveNetworkStatusNotification"), object: "reachableViaWWAN") | 29 | + NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWWAN, object: nil) |
| 29 | } | 30 | } |
| 30 | if status == .reachableViaWiFi { | 31 | if status == .reachableViaWiFi { |
| 31 | - /// 发送简单数据 | ||
| 32 | - NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "CNLiveNetworkStatusNotification"), object: "reachableViaWiFi") | 32 | + NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWiFi, object: nil) |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | 35 |