- #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");
- }
- }
For
such more Blogs you can visit to http://findnerd.com/NerdDigest
No comments:
Post a Comment