It's very easy in iOS ,just we need to import SystemConfiguration.framework in our project,the we need to write below few lines in class
+ (BOOL) currentNetworkStatus {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
BOOL connected;
BOOL isConnected;
const char *host = "www.apple.com";
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, host);
SCNetworkReachabilityFlags flags;
connected = SCNetworkReachabilityGetFlags(reachability, &flags);
isConnected = NO;
isConnected = connected && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
CFRelease(reachability);
if (!isConnected) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Network connection is unavalible.please chech your connection" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
return isConnected;
}
Enjoy with coding ...
0 comments:
Post a Comment