关于苹果官方网站Reachability检测网络的总结

Reachability类库版本在实时更新,官方参考demo及库下载地址,目前已到2.2的版本了:http://developer.apple.com/library/ios/#samplecode/Reachability/Listings/Classes_ReachabilityAppDelegate_m.html#//apple_ref/doc/uid/DTS40007324-Classes_ReachabilityAppDelegate_m-DontLinkElementID_4

之前项目中使用的方式如下:(实时监控网络的方法,2.0版本的) 注意:当程序在启动的时就没网络,实时监控会没有作用,也就是说,这样即使网络从无到有或是从有到无 都不会监控的到
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.hostReachable = [CheckNetReachability reachabilityWithHostName:@"www.google.com"];
    [self.hostReachable startNotifier];
   
    return YES;
}

#pragma mark - check the network

- (void)reachabilityChanged:(NSNotification *)notification {
    Reachability *curReach = [notification object];
    NetworkStatus status = [curReach currentReachabilityStatus];
    if (status == NotReachable) {
        [AlertBox showConfirm:nil message:@"已失去网络连接!" firstButtonTitle:@"好的" secondButtonTitle:nil delegate:self tag:0];
       。。。。。。。。。
    }else{
        if (!_isFirstLoad) {
            [AlertBox showConfirm:nil message:@"已连接上网络!" firstButtonTitle:@"好的" secondButtonTitle:nil delegate:self tag:0];
            。。。。。。。。。。。。。。
    }
}
posted @ 2012-09-03 11:05  SEC.VIP_网络安全服务  阅读(137)  评论(0编辑  收藏  举报