How to get change in network connection notification from iOS Reachability Class?

后端 未结 5 1984
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 05:24

Hi I want to capture whenever user gets a network connectivity in my application for this I have added apples Reachability class and below is the snippet I am using in my ap

5条回答
  •  自闭症患者
    2020-12-09 06:02

    Simplest of ways:

    reach = [Reachability reachabilityWithHostName:@"www.google.com"];
     reach.reachableBlock = ^(Reachability *reach){
        NSLog(@"Reachable");
    };
    
    reach.unreachableBlock = ^(Reachability *reach){
        NSLog(@"Unreachable");
    };
    [reach startNotifier];
    

    Everytime there is a change in network,respective blocks will be called.

提交回复
热议问题