开发者

Check Internet Connection

开发者 https://www.devze.com 2023-02-15 23:20 出处:网络
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?

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消