Please try this, it will help you (Swift 4)
1) Install Reachability via CocoaPods or Carthage: Reachability
2) Import Reachability and Use in Network Class
import Reachability
class Network {
private let internetReachability : Reachability?
var isReachable : Bool = false
init() {
self.internetReachability = Reachability.init()
do{
try self.internetReachability?.startNotifier()
NotificationCenter.default.addObserver(self, selector: #selector(self.handleNetworkChange), name: .reachabilityChanged, object: internetReachability)
}
catch {
print("could not start reachability notifier")
}
}
@objc private func handleNetworkChange(notify: Notification) {
let reachability = notify.object as! Reachability
if reachability.connection != .none {
self.isReachable = true
}
else {
self.isReachable = false
}
print("Internet Connected : \(self.isReachable)") //Print Status of Network Connection
}
}
3) Use like Below where You need.
var networkOBJ = Network()
// Use "networkOBJ.isReachable" for Network Status
print(networkOBJ.isReachable)