I have an app that cannot load anything if it does not have access to the internet. In my app delegate I use this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Check for internet
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
// Internet is not reachable
internetReachableFoo.unreachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is an example alert!" delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
exit(0);
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Someone broke the internet :(");
});
};
[internetReachableFoo startNotifier];
return YES;
}
The checking for the internet is done from this response Link and Then I want to show an alert box that tells the user it wont work without internet and then close the app. Currently I have the exit(0);
which I am aware that apple wont accept therefore on my alert view I am needing the ok button to close the app (if apple allows that). My problem is I am not sure how to close an app especially with a UIAlert view (I am fairly new to iOS) and if that is the case to show the alert view, I want the app to stop loading everything else when the alert view is up if it doesn't have internet because the app will just crash anyway (again if apple allows you to stop the app from continuing to load) How can I go about this in an apple approved way?