I'm using the popular Reachability framework (https://github.com/tonymillion/Reachability) in my app and I'm testing reachability on a real device (though it's exactly the same behavior on simulator too).
Here is my code (I'm strongly referencing the Reachability instance as an instance variable in my app delegate):
@implementation AppDelegate{
Reachability *reachability;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[...]
//this code is reached and called with no issues.
reachability = [Reachability reachabilityWithAddress:@"myreachabledomain.com"];
[reachability startNotifier];
return YES;
}
In somewhere else (again, strongly referenced):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityDidChange:)
name:kReachabilityChangedNotification object:nil];
[...]
-(void)reachabilityDidChange:(NSNotification*)note{
NSLog(@"hello");
}
However, I never get to see that "hello" (or hit the breakpoint). My domain is perfectly accessible. I toggle my phone's internet connectivity by permanently setting cellular data off, then running my app and toggling WiFi (yep, it connects to WiFi without issues and I can browse the internet).
What am I doing wrong? (I'm on iPhone 7 Plus, iOS 10.3.1)
UPDATE:
- I've tried
google.cominstead of my custom domain, no avail. - I've tried registering for notification before starting listening, no avail.
- I've tried using the block-based methods instead of notification center, no avail.
startNotifier. Btw: I'd prefer the block based API. - vadian