开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜