0

My app crashes every time the network status changes from no network to network or vice versa at the following line with EXC_BAD_ACCESS:

    dispatch_async(dispatch_get_main_queue(), ^{
        [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification 
                                                            object:self];
    });

Im calling through app delegate using:

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

    internetReach = [Reachability reachabilityForInternetConnection];
    [internetReach startNotifier];
    [self checkNetworkStatus:nil];

and

-(void) checkNetworkStatus:(NSNotification *)notice
{
    // called after network status changes
    NetworkStatus internetStatus = [internetReach currentReachabilityStatus];
    switch (internetStatus)
    {
        case NotReachable:
        {
            NSLog(@"The internet is down.");
            break;
        }
        case ReachableViaWiFi:
        {
            NSLog(@"The internet is working via WIFI.");
            break;
        }
        case ReachableViaWWAN:
        {
            NSLog(@"The internet is working via WWAN.");
            break;
        }
    }

}

Anyone know how to fix this?

Matt
  • 2,920
  • 6
  • 23
  • 33

1 Answers1

0

This might help you: Reachability Classes crashing program - not sure why

I had a problem with deallocating Reachability objects on a different thread to the one they were created on. I see you're allocating Reachability on the main queue, are you deallocating there too?

Community
  • 1
  • 1
BYZZav
  • 1,418
  • 1
  • 19
  • 35