swift 监听网络状态

func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

AFNetworkReachabilityManager.sharedManager().startMonitoring()
AFNetworkReachabilityManager.sharedManager().setReachabilityStatusChangeBlock { (status) in
switch status {
case .UnkNown:
JLToast.makeText("当前网络未知",duration: 3).show(UIApplication.sharedApplication().keyWindow)
case .NotReachable:
JLToast.makeText("当前网络不可以用,请检查!",duration: 3).show(UIApplication.sharedApplication().keyWindow)
case .ReachableViaWiFi:
break
case .ReachableViaWWAN:
break

}
}

//写你的代码


return true
}




func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources,save user data,invalidate timers,and store enough application state @R_568_4045@ion to restore your application to its current state in case it is terminated later. // If your application supports background execution,this method is called instead of applicationWillTerminate: when the user quits. AFNetworkReachabilityManager.sharedManager().stopMonitoring() } func applicationWillEnterForeground(application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. AFNetworkReachabilityManager.sharedManager().startMonitoring() }

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...