iOS 使用 Alamofire 实时监测网络状况

xiaoxiao2021-02-28  3

最近在用Swift写工程,,网络请求用的是Alamofire,在翻看这个库的时候发现 NetworkReachabilityManager 可以进行网络监察,废话不多说直接上代码吧,有兴趣的朋友可以去深入研究(https://github.com/Alamofire/Alamofire.git)

let manager = NetworkReachabilityManager(host: "https://github.com/Alamofire/Alamofire.git") func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. manager!.listener = { status in switch status { case .notReachable: print("notReachable") case .unknown: print("unknown") case .reachable(.ethernetOrWiFi): print("ethernetOrWiFi") case .reachable(.wwan): print("wwan") } } manager!.startListening() return true }

转载请注明原文地址: https://www.6miu.com/read-450311.html

最新回复(0)