private void reachabilityChanged(SCNetworkReachabilityFlags flags) { if (reachabilityListener != null) { if (isReachableWithFlags(flags)) { reachabilityListener.onReachable(this); } else { reachabilityListener.onUnreachable(this); } reachabilityListener.onChange(this, flags); } // this makes sure the change notification happens on the MAIN THREAD DispatchQueue.getMainQueue().async( () -> NSNotificationCenter.getDefaultCenter().postNotification(REACHABILITY_CHANGE_NOTIFICATION, this)); }