Following code will help you to detect the change in network availability.
Download the reachablity class from here :
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
#import "Reachability.h"
Then put following code in your App delegate didFinishLaunchingWithOptions method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable)
{
//No internet
}
else if (status == ReachableViaWiFi)
{
//WiFi
}
else if (status == ReachableViaWWAN)
{
//3G
}
[[NSNotificationCenter defaultCenter] postNotificationName:notifcationstr object:status]
}
Set Notification Observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NetworkreachablityChanging:) name:kReachabilityChangedNotification object:nil];
- (void)NetworkreachablityChanging:(NSNotification *)notification {
Reachability *reachability = (Reachability *)[notification object];
if ([reachability isReachable]) {
NSLog(@"online");
} else {
NSLog(@"offline");
}
}
0 Comment(s)