saidaltintop
10/17/2019 - 1:21 PM

Reachability


@property (nonatomic) Reachability *hostReachability;


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
   //Change the host name here to change the server you want to monitor.
   NSString *remoteHostName = @"www.apple.com";
   self.hostReachability = [Reachability reachabilityWithHostName:remoteHostName];
   [self.hostReachability startNotifier];
   [self updateInterfaceWithReachability:self.hostReachability]; (edited) 


/ MARK: Reachability
- (void) reachabilityChanged:(NSNotification *)note
{
   Reachability* curReach = [note object];
   NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
   [self updateInterfaceWithReachability:curReach];
}
- (void)updateInterfaceWithReachability:(Reachability *)reachability
{
   if (reachability == self.hostReachability)
   {
       NetworkStatus netStatus = [reachability currentReachabilityStatus];
       [_activityIndicator startAnimating];
       self->_activityIndicator.hidden = false;
       if (netStatus == NotReachable) {
           NSLog(@"internet yok");
           [self->_activityIndicator stopAnimating];
           self->_activityIndicator.hidden = true;
       }else{
           NSLog(@"internete bağlandı");
       }
   }
}
- (void)dealloc
{
   [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
}