Reachability注意事项

@property (nonatomic, strong) Reachability *reacability;

ps: 
   注意事项:如果Reachability.m为MRC的,则初始化时,Reachability的对象一定要强引用,否则创建后会立刻释放掉,导致不能监听到。ARC时可以忽略。

self.reacability = [Reachability reachabilityWithHostName:@"www.baidu.com"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationNetworkStatusChanged:) name:kReachabilityChangedNotification object:nil];

[self.reacability startNotifier];

- (void)applicationNetworkStatusChanged:(NSNotification *)noti {

    switch (self.reacability.currentReachabilityStatus) {
          case NotReachable:
          {
              
          }
          break;
          case ReachableViaWWAN:
          {
            
          }
          break;
          case ReachableViaWiFi:
          {
                
          }
        break;
        default:
        {
        }
        break;
}

}

你可能感兴趣的:(Reachability注意事项)