我已經創建了一個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在提供動態更新,而不必手動檢查互聯網更加實用和有用連接。 –