2013-07-29 110 views
-1

我的問題是,我實現了一個警報,允許告訴用戶在打開應用程序時沒有互聯網連接,白色視圖顯示警報。 我的代碼是:應用程序不能在後臺模式下運行ios

Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"]; 

if([reach isReachable]) 
{ 
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; 
MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController; 
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"navigationController"]; 

UIViewController *rightSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"rightSideMenuViewController"]; 

[container setRightMenuViewController:rightSideMenuViewController]; 
[container setCenterViewController:navigationController]; 
} 
else 
{ 
    connection = @"Please connect to Internet"; 
    [self showAlarm:connection]; 
    [reach startNotifier]; 
} 

    - (void)showAlarm:(NSString *)text 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Connection" 
     message:text delegate:self 
     cancelButtonTitle:@"الغاء" 
     otherButtonTitles:nil]; 
    [alertView show]; 

} 

以上的方法,允許,如果有像下面的截圖沒有任何聯繫,以提醒用戶:現在 enter image description here

,如果我有互聯網連接,並嘗試打開應用程序(點擊應用程序圖標),白色頁面顯示(仍然在後臺),

enter image description here

因爲我最後一次打開應用程序,療法e沒有連接,所以白色頁面顯示,所以當我再次打開應用程序(現在我有互聯網)時,應用程序的主頁面必須啓動,但因爲它保存了最後打開的視圖,所以白色頁面再次顯示,如果我雙擊iPhone的主要按鈕並關閉應用程序,並再次運行它工作正常, 希望你現在得到了我。 是真的如果我把(應用程序不在後臺運行)轉到YES?或者您有另一種解決方案,如果是,請告訴我該選項(應用程序不在後臺運行)是做什麼的?如果不方便,使用它是否安全? 謝謝

+0

請分享代碼,到目前爲止你做了什麼? – Suryakant

+0

Plz詳細說明你的問題......在閱讀你的問題後,我無法確定你想要的東西嗎?你的白色背景是一個問題,或者你正在檢查互聯網連接或者什麼? – Ajay

回答

0

不管你什麼時候再來,都可以在你的課堂上試試這個。

- (void)viewWillAppear:(BOOL)animated 
{ 
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(handleEnterForeground:) name: @"UIApplicationDidBecomeActiveNotification" object: nil]; 
} 

- (void) handleEnterForeground: (NSNotification*) sender 
{ 
    [self checkYourConnection_Method]; 
} 

NSNotification告訴應用程序,如果它會在前景和背景來。
然後再次調用「互聯網連接」的方法。

希望這會幫助你。

謝謝。