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];
        }
    }

  • 相关阅读:
    懂得拐弯,是人生大智慧!
    人心如落叶
    人生聚散,一切随缘!
    35岁以后你还能干嘛?
    人品好,自带光芒
    有一种心境,叫顺其自然
    304. Range Sum Query 2D
    303. Range Sum Query
    301. Remove Invalid Parentheses
    297. Serialize and Deserialize Binary Tree
  • 原文地址:https://www.cnblogs.com/chenfulai/p/2124982.html
Copyright © 2011-2022 走看看