2011-10-18 8 views
5

Używam tego kodu do sprawdzenia połączenia z internetem, ale jestem coraz awarię mówiąc +[Reachability reachabilityForInternetConnection]: unrecognized selector sent to class 0xcbe0c8App upaść podczas korzystania osiągalności klas w celu sprawdzenia połączenia internetowego

mam importowane Reachability .h/.m i ram systemconfig. Crash przy linii self.internetRechable = [[Reachability reachabilityForInternetConnection] retain];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil]; 

    self.internetRechable = [[Reachability reachabilityForInternetConnection] retain]; 
    [self.internetRechable startNotifier]; 

    // check if a pathway to a random host exists 
    self.hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain]; 
    [self.hostReachable startNotifier]; 

- (void) checkNetworkStatus:(NSNotification *)notice 
{ 
    // called after network status changes 

    NetworkStatus internetStatus = [self.internetRechable currentReachabilityStatus]; 
    switch (internetStatus) 
    { 
     case NotReachable: 
     { 
      NSLog(@"The internet is down."); 
//   self.internetActive = NO; 
      break; 
     } 
     case ReachableViaWiFi: 
     { 
      NSLog(@"The internet is working via WIFI."); 
//   self.internetActive = YES; 
      break; 
     } 
     case ReachableViaWWAN: 
     { 
      NSLog(@"The internet is working via WWAN."); 
//   self.internetActive = YES; 
      break; 
     } 
    } 

    NetworkStatus hostStatus = [self.hostReachable currentReachabilityStatus]; 
    switch (hostStatus) 
    { 
     case NotReachable: 
     { 
      NSLog(@"A gateway to the host server is down."); 
//   self.hostActive = NO; 
      break; 
     } 
     case ReachableViaWiFi: 
     { 
      NSLog(@"A gateway to the host server is working via WIFI."); 
//   self.hostActive = YES; 
      break; 
     } 
     case ReachableViaWWAN: 
     { 
      NSLog(@"A gateway to the host server is working via WWAN."); 
//   self.hostActive = YES; 
      break; 
     } 
    } 
} 
+0

Nie, robiłem '@class Reachability' a ja importowane jako dobrze – Jon

+0

Tak, ive importowane pliki i zrobiłem' #import "Reachability.h" 'itp – Jon

+0

zrobiłem, że jego awaria w 'Dostępności * newReach = [osiągalność osiągalności dlaInternetConnection];' – Jon

Odpowiedz

1

upewnić się, że jest w Reachability wersji: 2.2, kilka rzeczy zmieniły ostatnio, że może powodować thiscrash jeśli nie za pomocą 2.2.

Oto linki do version2.2 z Reachability.h i Reachability.m

Ponadto, jeśli to pomoże, heres mojego kodu pracy dla tego samego zadania :.

W moim appDidFinishLaunching (hostReachable i internetReachable są Ivars mojego app delegata):

//.... 
if ([[Reachability reachabilityWithHostName:@"google.com"] currentReachabilityStatus] == NotReachable) { 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil]; 
    internetReachable = [[Reachability reachabilityForInternetConnection] retain]; 
    [internetReachable startNotifier]; 
    hostReachable = [[Reachability reachabilityWithHostName:@"google.com"] retain]; 
    [hostReachable startNotifier]; 
} 

Następnie callback:

- (void)checkNetworkStatus:(NSNotification *)notice { 
    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus]; 
    switch (internetStatus) { 
     case NotReachable: 
      self.internetActive = NO; 
      break; 
     case ReachableViaWiFi: 
      self.internetActive = YES; 
      break; 
     case ReachableViaWWAN: 
      self.internetActive = YES; 
      break; 
    } 
    NetworkStatus hostStatus = [hostReachable currentReachabilityStatus]; 
    switch (hostStatus) { 
     case NotReachable: 
      self.hostActive = NO; 
      break; 
     case ReachableViaWiFi: 
      self.hostActive = YES; 
      break; 
     case ReachableViaWWAN: 
      self.hostActive = YES; 
      break; 
    } 
    if (internetActive && hostActive) { 
     [self refreshAllData]; 
    } 
} 
-1

Należy zwrócić ARC off. Go zbudować faz, wybierz ten nazywa i kliknij dwukrotnie na prawej krawędzi i wpisz

-fno -objc -arc 

myślę, że można zasnąć zachować kod zbyt.

Powiązane problemy