I have a view that i display when there is no internet connection, and if there is no internet connection I check to see if it has be restored, with this method. Which is first called in viewDidLoad
-(void)checkInternet {
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
NetworkStatus netStatus = [internetReach currentReachabilityStatus];
switch (netStatus){
case ReachableViaWWAN:{
isReachable = YES;
NSLog(@"4g");
noInternetView.hidden = YES;
break;
}
case ReachableViaWiFi:{
isReachable = YES;
noInternetView.hidden = YES;
NSLog(@"wifi");
break;
}
case NotReachable:{
NSLog(@"NONE");
noInternetView = [[CheckInternetView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:noInternetView]; //IT IS NOT ADDED??
isReachable = NO;
[self checkInternet];
break;
}
}
}
And the method is called over and over again if there is no internet, but why isn't noIntenertView
coming onto the view controller?
EDIT
Here is the CheckInternetView Class
#import "CheckInternetView.h"
@implementation CheckInternetView
- (id)initWithFrame:(CGRect)frame {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
self = [super initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
if (self) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 60)];
label.textAlignment = NSTextAlignmentCenter;
label.numberOfLines = 2;
[label setCenter:CGPointMake(self.frame.size.width / 2 , self.frame.size.height / 2 - 25)];
label.text = @"You've lost your internet connection. Please connect to internet.";
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame = CGRectMake(0, 0, 80, 80);
[spinner setCenter:CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2 + 40)];
[spinner startAnimating];
label.textColor = whiteColorAll;
spinner.color = whiteColorAll;
[self setBackgroundColor:[UIColor blackColor]];
[self addSubview: spinner];
[self addSubview: label];
}
return self;
}