Hi all,
I'm working on an app that will load some file from the web and parse it into the app.
I have a problem, since I'm using Reachability class to know if the device is having a internet connection and if the host is reachable.
If one of these 2 are false, then I'm presenting an different view controller, with an anouncement that, the user has no internet, or that the server is down.
This is my code:
It does work fine, however sometimes it does not work. The screen stays black. When I double tap the home button it does show me the 'errorView' but in app the screen stays black. In xCode i'm having this warning:
I'm working on an app that will load some file from the web and parse it into the app.
I have a problem, since I'm using Reachability class to know if the device is having a internet connection and if the host is reachable.
If one of these 2 are false, then I'm presenting an different view controller, with an anouncement that, the user has no internet, or that the server is down.
This is my code:
Code:
-(void)viewDidAppear:(BOOL)animated {
[indicator startAnimating];
CompanyappDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
internetReachable = [Reachability reachabilityForInternetConnection];
[internetReachable startNotifier];
hostReachable = [Reachability reachabilityWithHostName:@"www.mydomain.com"];
[hostReachable startNotifier];
loadData = [NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(loadData) userInfo:nil repeats:NO];
}
-(void)loadData {
if(internetActive && hostActive) {
//Ok, we have connection and the host is alive.
//Doing all my loading data in here.
} else {
BOOL deviceIsIpad = NO;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
deviceIsIpad = YES;
}
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
if(!deviceIsIpad) {
mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
}
UIViewController *nextView = [mainStoryboard instantiateViewControllerWithIdentifier:@"errorView"];
[self presentViewController: nextView animated:YES completion:nil];
}
}
It does work fine, however sometimes it does not work. The screen stays black. When I double tap the home button it does show me the 'errorView' but in app the screen stays black. In xCode i'm having this warning:
Code:
Warning: Attempt to present <dataView: 0x95ab070> on <connectionLoss: 0x97801a0> whose view is not in the window hierarchy!
Last edited: