zoukankan      html  css  js  c++  java
  • oc中检测网络状态

        // 监测网络情况
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(reachabilityChanged:)
                                                     name: kReachabilityChangedNotification
                                                   object: nil];
        hostReach = [[Reachability reachabilityWithHostName:@"www.google.com"] retain];

        [hostReach startNotifier];

    - (void)reachabilityChanged:(NSNotification *)note {
        Reachability* curReach = [note object];
        NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
        NetworkStatus status = [curReach currentReachabilityStatus];

        if (status == NotReachable) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AppName"
                                  message:@"NotReachable"
                                  delegate:nil
                                  cancelButtonTitle:@"YES" otherButtonTitles:nil];
                                  [alert show];
                                  [alert release];
        }
    }

  • 相关阅读:
    回忆Partition算法及利用Partition进行快排
    2019春第七周作业
    2019春第六周作业
    2019春第五周作业
    2019年春季学期第四周作业。
    2019年春季学期第三周作业
    2019年春季学期第二周作业
    2019春第一周作业编程总结
    PTA编程总结2—币值转换
    第七周编程总结
  • 原文地址:https://www.cnblogs.com/chenfulai/p/2124982.html
Copyright © 2011-2022 走看看