我有一个应用程序,如果它无法访问互联网,它就无法加载任何内容。在我的应用程序委托中,我使用以下代码:
- (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;
}
互联网检查是从此响应链接完成的,然后我想显示一个警告框,告诉用户它在没有互联网的情况下无法工作,然后关闭应用程序。目前我有exit(0);
我知道苹果不会接受的,因此在我的警报视图中我需要确定按钮来关闭应用程序(如果苹果允许的话)。我的问题是我不确定如何关闭应用程序,尤其是使用 UIAlert 视图(我对 iOS 还很陌生),如果是显示警报视图的情况,我希望应用程序在警报视图时停止加载其他所有内容如果它没有互联网,它就会启动,因为应用程序无论如何都会崩溃(再次,如果苹果允许您阻止应用程序继续加载)我怎样才能以苹果批准的方式解决这个问题?