How to use reachability class to detect valid internet connection?

前端 未结 7 638
遇见更好的自我
遇见更好的自我 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!");
    }
    

提交回复
热议问题