Search code examples
ios5unrecognized-selectornsnotification

[NSConcreteNotification isReachable]: unrecognized selector sent to instance


I'm trying to get ASIReachability to work in my app which works when the connection isn't there but when the connection exists it give the following error:

2013-04-08 12:26:20.501 Your Llanelli Companion[1576:207] -[NSConcreteNotification isReachable]: unrecognized selector sent to instance 0x7d84d30

I can't seem to remedy this and it's beginning to bug me.

.m file:

- (void) CheckIfAInternetConnectionExists
{
    Reachability *reach = [[Reachability reachabilityWithHostName:@"http://176.31.101.181:8020/listen.pls"]retain ];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                                object:nil];
    [reach startNotifier];    
}

- (void) reachabilityChanged:(Reachability *)reach {
    if ([reach isReachable ]) {
        NSLog(@"connection");
        ServerFound = YES;
        [self PrepareStream];
    } else{
        NSLog(@"no connection");
        ServerFound = NO;
        [self PrepareStream];
    }
}

If someone can figure this out for me I'd be very grateful.


Solution

  • When you receive the notification, the parameter to your reachabilityChanged: method will be the notification itself. To get the Reachability object, you'll need to get it from the notification by sending -[NSNotification object] to the notification.

    So something like this should work:

    - (void) reachabilityChanged:(NSNotification *)note {
    
        Reachability *reach = [note object];
    
        if ([reach isReachable ]) {
            NSLog(@"connection");
            ServerFound = YES;
        } else{
            NSLog(@"no connection");
            ServerFound = NO;
        }
    
        [self PrepareStream];
    
      }