import UIKit
import ReachabilitySwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
var reachability: Reachability!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow()
reachability = Reachability.init()
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged),name: ReachabilityChangedNotification, object: nil)
do {
try reachability!.startNotifier()
} catch {
print("could not start reachability notifier")
}
return true
}
func reachabilityChanged() {
DispatchQueue.main.async {
//self.networkStatusChanged()
print(self.reachability.currentReachabilityStatus)
}
}
}
I had same issue. but fixed it.
It was because I created reachability object inside wiewDidLoad function. I fixed it and moving declaration in class.
In Reachability class they called stopNotifire on deinit function.
Bro, I've found that there was something wrong with my mackbook pro. Don't know why but in my macbook simulator this code wont work but when I ran the app in a real device the code worked like a charm.
It was because I created reachability object inside wiewDidLoad function. I fixed it and moving declaration in class
@ashleymills Could you please add this info to README ?
Most helpful comment
I had same issue. but fixed it.
It was because I created reachability object inside wiewDidLoad function. I fixed it and moving declaration in class.