O2ReachabilityManager.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // O2ReachabilityManager.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2017/6/2.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. import Alamofire
  10. import CocoaLumberjack
  11. class O2ReachabilityManager {
  12. static let sharedInstance = O2ReachabilityManager()
  13. private let networkReachabilityManager:NetworkReachabilityManager!
  14. private init() {
  15. networkReachabilityManager = NetworkReachabilityManager()
  16. networkReachabilityManager.listener = { netStatus in
  17. switch netStatus {
  18. case .unknown:
  19. DDLogError("未知网络 unknown")
  20. break;
  21. case .notReachable:
  22. DDLogError("没有联网,请连接网络 notReachable")
  23. break;
  24. case .reachable:
  25. let msg = "网络是可用的,"
  26. if self.networkReachabilityManager.isReachableOnWWAN {
  27. DDLogInfo("\(msg)现在使用的是移动网络")
  28. }
  29. if self.networkReachabilityManager.isReachableOnEthernetOrWiFi {
  30. DDLogInfo("\(msg)现在使用的是WiFi")
  31. }
  32. break;
  33. }
  34. }
  35. }
  36. public func startListening() -> Void {
  37. self.networkReachabilityManager.startListening()
  38. }
  39. public func stopListening() -> Void {
  40. self.networkReachabilityManager.stopListening()
  41. }
  42. }