I use lib named RealReachability that getting currently reachability status in real time!
And i have a function that getting data from my server.
Now its look like this:
RealReachability.sharedInstance().reachabilityWithBlock { (status: ReachabilityStatus) in
switch status {
case .RealStatusNotReachable:
break
default:
operationQueue.addOperationWithBlock {
GettingDataFromServer() }
}
}
Also RealReachability can send Notification when Reachability status changed. Its look like this:
var operationQueue = NSOperationQueue()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyController.networkChanged), name: kRealReachabilityChangedNotification, object: nil)
func networkChanged(notification: NSNotification) {
print("NetworkChanged")
let status = RealReachability.sharedInstance().currentReachabilityStatus()
switch status {
case .RealStatusNotReachable:
print("try to stop Operation")
operationQueue.cancelAllOperations()
ShowInternetConnectionErrorView()
default:
print("Internet OK!")
}
}
What do I need to stop GettingDataFromServer() function execution when reachability status changed to .RealStatusNotReachable