您仍然可以在Swift中使用可达性. Logan对于如何将objective-c文件添加到桥接头
here中有一个很好的答案.一旦您设置了桥接头,就可以从Swift代码调用Reachability方法.这样的事情会起作用:
原文链接:https://www.f2er.com/swift/319702.htmlclass func hasConnectivity() -> Bool { let reachability: Reachability = Reachability.reachabilityForInternetConnection() let networkStatus: Int = reachability.currentReachabilityStatus().value return networkStatus != 0 }