Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification is only fired once. #221

Closed
rjt3662 opened this issue Aug 20, 2017 · 3 comments
Closed

Notification is only fired once. #221

rjt3662 opened this issue Aug 20, 2017 · 3 comments

Comments

@rjt3662
Copy link

rjt3662 commented Aug 20, 2017

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)
    }
}

}

@gormat
Copy link

gormat commented Aug 27, 2017

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.

@rjt3662
Copy link
Author

rjt3662 commented Aug 28, 2017

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.

@rjt3662 rjt3662 closed this as completed Aug 28, 2017
@MihaelIsaev
Copy link

MihaelIsaev commented Sep 21, 2017

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants