Problems with reachability observer in Mavericks / Xcode 5
Problems with reachability observer in Mavericks / Xcode 5
- Subject: Problems with reachability observer in Mavericks / Xcode 5
- From: Pax <email@hidden>
- Date: Tue, 12 Nov 2013 13:50:12 +0000
Here's an odd one. It works before Mavericks (Xcode 5) - and doesn't work now.
I've been playing with Reachability (https://developer.apple.com/Library/ios/samplecode/Reachability/Introduction/Intro.html). Apple's example is for iOS, but with a few small mods it worked fine on Mac OS X. I want to detect when the network connection changes, and I've set it up like so:
- (void) reachabilityChanged: (NSNotification* )note
{
NSLog (@"**** Reachability changed");
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
hostReach = [Reachability reachabilityWithHostName: @"www.apple.com"];
[hostReach startNotifier];
[self updateInterfaceWithReachability: hostReach];
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
[self updateInterfaceWithReachability: internetReach];
wifiReach = [Reachability reachabilityForLocalWiFi];
[wifiReach startNotifier];
[self updateInterfaceWithReachability: wifiReach];
}
Where kReachabilityChangedNotification is defined as #define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"
The reachability code is as per Apple's example. Previously, the code would execute on start ('**** Reachability changed' output to the log), and subsequently every time the WiFi or cabled connection changed. Now, on Mavericks / Xcode 5, it executes once on start (so it knows that the current state is) and never changes again - no matter how long I wait.
Since it's not getting to reachabilityChanged, I'm guessing that the name (kReachabilityChangedNotification) has changed in Mavericks. Is anyone aware of any changes that have been made in this area? Google has rather turned up a blank in my investigations.
Thanks in advance for any help that you can offer with this problem.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden