reachabilityWithAddress no funciona en la progtwigción Objective C

Quiero verificar que un server esté en vivo o no con ip, por ejemplo, 74.125.71.104 (ip de Google)

// asignar un object de accesibilidad

`struct sockaddr_in address; address.sin_len = sizeof(address); address.sin_family = AF_INET; address.sin_port = htons(80); address.sin_addr.s_addr = inet_addr("74.125.71.104");` Reachability *reach = [Reachability reachabilityWithAddress:&address]; 

pero los que no funcionan.

Cuando cambio a reachabilityWithHostname , está funcionando.

#include <arpa/inet.h>

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; struct sockaddr_in address; address.sin_len = sizeof(address); address.sin_family = AF_INET; address.sin_port = htons(8080); address.sin_addr.s_addr = inet_addr("216.58.199.174"); //google ip self.internetReachability = [Reachability reachabilityWithAddress:&address]; [self.internetReachability startNotifier]; [self updateInterfaceWithReachability:self.internetReachability]; 

EDITAR

Según sus comentarios, no se llaman los bloques de scope. Siempre utilizo notifications que no son muy conscientes de los bloques de accesibilidad. Entonces, prefiero usar las notifications de la siguiente manera.

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; struct sockaddr_in address; address.sin_len = sizeof(address); address.sin_family = AF_INET; address.sin_port = htons(8080); address.sin_addr.s_addr = inet_addr("216.58.199.174"); self.internetReachability = [Reachability reachabilityWithAddress:&address]; [self.internetReachability startNotifier]; [self updateInterfaceWithReachability:self.internetReachability]; 

Ahora cada vez que su estado de Internet cambia el método reachabilityChanged se disparará con la instancia de accesibilidad 🙂

 - (void) reachabilityChanged:(NSNotification *)note { Reachability* curReach = [note object]; [self updateInterfaceWithReachability:curReach]; } 

Finalmente, implementar updateInterfaceWithReachability como

 - (void)updateInterfaceWithReachability:(Reachability *)reachability { NetworkStatus netStatus = [reachability currentReachabilityStatus]; switch (netStatus) { case NotReachable: { //not reachable } break; case ReachableViaWWAN: case ReachableViaWiFi: { //reachable via either 3g or wifi } break; } } 

Espero que esto ayude.