
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 information 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() }
总结以上是内存溢出为你收集整理的swift 监听网络状态全部内容,希望文章能够帮你解决swift 监听网络状态所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)