How to use reachability class to detect valid internet connection?

前端 未结 7 636
遇见更好的自我
遇见更好的自我 2020-11-29 23:24

I\'m new to iOS development and am struggling to get the reachability.h class to work. Here is my code for view controller:

- (void)viewWillAppear:(BOOL)anim         


        
相关标签:
7条回答
  • 2020-11-30 00:19

    The very simplest method (once you have added Reachability to your project):

    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    if (reachability.isReachable) {
        NSLog(@"We have internet!");
    } else {
        NSLog(@"No internet!");
    }
    
    0 讨论(0)
提交回复
热议问题