swift 监听网络状态

swift 监听网络状态,第1张

概述 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {                  AFNetworkReachabilityManager.sharedManager().startMonitori 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 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 监听网络状态所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1077511.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存