I was looking over the Reachability sample project on developer.apple.com and found that it was a large project just to verify you had network connectivity.
First part of the question is "What is the minimum code required to find out if the device can reach a 3G or wifi network?"
And next should this be done inside the appDelegate (on start) or inside the first View Controller that is launched?
Thank you in advance
You can use NetworkReachabilityManager class from Alamofire and configure the isConnectedToInternet() method as per your need. I am only checking if the device is connected to internet or not. print("Yes! internet is available.")
Open the Wifi app. Tap the icon tab, then Network check. On the network check screen, tap Test Wi-Fi. We'll test one Wifi point at a time, showing speeds for each device connected to that Wifi point.
To check if your iOS mobile device is connected to Wi-Fi:From the main screen of your device, look for and open Settings. With Settings open, look for the Wi-Fi field. Off - the Wi-Fi antenna is currently disabled. Not Connected - Wi-Fi is turned on, but your device is not currently connected to a network.
It's not large, it really does what you want. If it is too big for you, you can extract what you need only like reachabilityForLocalWiFi. But I'm afraid that it will not be much smaller.
Yes, you can use reachability in your application delegate or inside the first view controller.
Reachability notification registration ...
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(networkReachabilityDidChange:)
name:kReachabilityChangedNotification
object:nil];
__reachability = [[Reachability reachabilityWithHostName:@"www.google.com"] retain];
[__reachability startNotifier];
... callback method example ...
- (void)networkReachabilityDidChange:(NSNotification *)notification {
Reachability *reachability = ( Reachability * )[notification object];
if ( reachability.currentReachabilityStatus != NotReachable ) {
// Network is available, ie. www.google.com
} else {
// Network is not available, ie. www.google.com
}
}
... do not forget to stop notifications, remove observer and release rechability object.
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