我已经创建了一个iPhone应用程序,我想检查互联网connectivity.At应用程序的委托方法我写互联网检查iOS应用程序
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
viewController1 = [[ViewController1 alloc] initWithNibName:@"ViewController1" title:firstTabTitleGlobal bundle:nil];
viewController2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" title:secondTabTitleGlobal bundle:nil];
newNavController = [[UINavigationController alloc] initWithRootViewController:viewController1];
userNavController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:newNavController,userNavController,nil]
Reachability *r = [Reachability reachabilityWithHostName:globalHostName];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
[self showAlert:globalNetAlertTitle msg:globalNetAlertMsg];
[activityIndicator stopAnimating];
}
else
{
[activityIndicator stopAnimating];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
}
我的代码是确定的didFinishLaunchingWithOptions方法,因为在没有互联网连接,然后放映alert.But问题是没有interner然后default.png显示。当我再次运行应用程序时,应用程序将从显示default.png运行。没有发生。 在此先感谢。
我认为你的答案修复设置了由提问者的问题 - 对了投票的原因,但使用NSNotifications在提供动态更新,而不必手动检查互联网更加实用和有用连接。 –