如何在
Swift中检查网络状态?在Objective-C中Reachability.h .m文件可用.现在怎么办?我如何检查我是在线还是离线?
您仍然可以在Swift中使用可达性. Logan对于如何将objective-c文件添加到桥接头
here中有一个很好的答案.一旦您设置了桥接头,就可以从Swift代码调用Reachability方法.这样的事情会起作用:
class func hasConnectivity() -> Bool { let reachability: Reachability = Reachability.reachabilityForInternetConnection() let networkStatus: Int = reachability.currentReachabilityStatus().value return networkStatus != 0 }