Check Internet Connection
I've tried checking if there is a connection to google.com But this method doesn't work correctly? Can you show me my fault? Yours Raphael
- (BOOL)networkCo开发者_高级运维nnected {
SCNetworkReachabilityFlags flags = 0;
SCNetworkReachabilityRef netReachability;
BOOL retrievedFlags = NO;
netReachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"http://www.google.com" UTF8String]);
if (netReachability) {
retrievedFlags = SCNetworkReachabilityGetFlags(netReachability, &flags);
CFRelease(netReachability);
}
if (!retrievedFlags || !flags) {
NSLog(@"no");
return NO;
}
NSLog(@"yes");
return YES;
}
You should better check Apple Reacheability example
Can you use this in objective-c for iPhone?
DWORD flags, reserved;
flags = reserved = 0;
if(!InternetGetConnectedState(&flags, reserved))
{
// No internet connection
} else {
// Have internet connection
}
精彩评论