去这里http://developer.apple.com/iphone/library/samplecode/Reachability/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007324-Intro-DontLinkElementID_2 下载Reachability.m和Reachability.h,然后添加到你的项目里面,在需要测试网络连接class里面写这样的一个方法

- (BOOL)testConnection {
    BOOL result = YES;
    Reachability *reach=[Reachability sharedReachability];
    [reach setHostName:@“你自己输入一个网址来做ping”];
    NetworkStatus status;
    status=[reach remoteHostStatus];
    if (status == NotReachable) {
        result = NO;
    } else if (status == ReachableViaCarrierDataNetwork) {
        result = YES;
    } else if (status == ReachableViaWiFiNetwork) {
        result = YES;
    }else {
        result = NO;
    }
    return result;
}

相关文章:

  • 2018-09-19
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-10-23
猜你喜欢
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-06-23
  • 2022-12-23
相关资源
相似解决方案