// 监测网络情况
    [[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];
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-10-14
  • 2021-05-30
  • 2022-02-11
  • 2022-02-03
猜你喜欢
  • 2021-09-04
  • 2021-09-19
  • 2021-07-23
  • 2021-09-26
  • 2022-02-07
  • 2022-02-11
相关资源
相似解决方案