I'm trying to implement Reachability in my app. I have it in applicationDidFinishLaunching
. If my connection is really bad and I launch the app, Reachability takes forever and often crashes the app with an The application failed to launch in time
error message.
So instead, I tried putting the call to Reachability in a background thread. But when I do this, I no longer receive the Reachability notifications.
Where should I be calling Reachability?
Edit:
I added TonyMillions' Reachability code per the suggestion below, but I'm still getting the same application failed to load in time
error when in very bad network conditions. To reproduce what I'm seeing, go to Settings.app -> Developer -> Network Link Conditioner, turn it on and set it to 100% loss.
Does your app still load in that condition?
Use Tony Millions reachability project on Github.
https://github.com/tonymillion/Reachability
Then in my app delegate I just put in applicationdidfinishlaunching
self.reachability = [Reachability reachabilityForInternetConnection];
[self.reachability startNotifier];
Then when the status changes this will be called
#pragma mark - Reachability
- (void)reachabilityChanged:(NSNotification *)note {
NetworkStatus ns = [(Reachability *)[note object] currentReachabilityStatus];
if (ns == NotReachable) {
if (![self.networkAlert isVisible]) {
if ([self networkAlert] == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"\n\nNo Internet Connection" message:@"You require an internet connection to communicate with the server." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[self setNetworkAlert:alert];
}
[self.networkAlert show];
}
} else {
if ([self networkAlert] != nil) {
[self.networkAlert dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With