Search code examples
iosreachability

No visible @interface for reachability declares the selector startNotifier


i get this error: No visible @interface for reachability declares the selector startNotifier

i have included both Reachability.h and .m files. i am extremely new to objective-C and the error might be really tiny! but any help would be great!

my helloworldViewController.m

#import "helloworldViewController.h"
#import "Reachability.h"
#import <SystemConfiguration/SystemConfiguration.h>


@interface helloworldViewController ()

@end

@implementation helloworldViewController
@synthesize networkstatus;
@synthesize reach;



#pragma mark Reachability changed


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
        // Check network
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
    [self.reach startNotifer];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)reachabilityChanged:(NSNotification*)note
{
    Reachability* r = [note object];
    NetworkStatus ns = r.currentReachabilityStatus;

    if (ns == NotReachable)
    {
        NSString* msg = @"Network problems have rendered the iTunes store inaccessible; please try again later.";
        UIAlertView* av = [[UIAlertView alloc] initWithTitle:nil
                                                     message:msg
                                                    delegate:self
                                           cancelButtonTitle:@"Ok"
                                           otherButtonTitles:nil];
        [av show];
        //[av release];
    }
}


@end

and here is my helloworldViewController.h

#import <UIKit/UIKit.h>
#import "Reachability.h"

@interface helloworldViewController : UIViewController{


    Reachability* reach;
    IBOutlet UILabel *networkstatus;

}
@property(strong,nonatomic) UILabel *networkstatus;
@property (nonatomic, retain) Reachability* reach;

@end

Solution

  • You spelled the method incorrectly. Change this line:

    [self.reach startNotifer];
    

    to:

    [self.reach startNotifier];
    

    Since you are new, here are a few more suggestions:

    • Replace #import "Reachability.h" in the .h file with @class Reachability.
    • Get rid of the explicit ivars and the explicit @synthesize lines. Let the compiler generate these for you. This assumes you are using the latest compiler/Xcode.
    • You are being inconsistent in your properties. One is strong and the other is retain. If you are using ARC, use strong for both. If you are using MRC, using retain for both.
    • It is standard convention that class names begin with uppercase letters and methods and variables begin with lowercase. Both should use CamelCase. Change your class to HelloWorldViewController. Change networkstatus to networkStatus.