2010-08-23 27 views
1

每當收到推送通知時(應用程序正在運行),我需要顯示通知模式。我的應用程序有一個標籤欄,我已經通過將通知模式推送到標籤欄控制器來部分工作。接收推送通知時顯示模式

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {   
    NotificationViewController *vc = [[NotificationViewController alloc] init]; 
    [tabBarController presentModalViewController:vc animated:YES]; 
    [vc release]; 
} 

但是,這似乎失敗了,但是,當已經有一個不同的模式打開隱藏標籤欄控制器。什麼是確保在收到推送通知時顯示NotificationViewController始終爲的最佳方式,即使已經存在隱藏標籤欄控制器的模態打開?

回答

3

你可以做兩件事。首先是解散當前的模式控制器,但它可能會混淆用戶。第二件事情是這樣的事情:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {  
    UIViewController* currentController = tabBarController; 
    if ([currentController modalViewController] != nil) 
      currentController = [currentController modalViewController]; 

    NotificationViewController *vc = [[NotificationViewController alloc] init]; 
    [currentController presentModalViewController:vc animated:YES]; 
    [vc release]; 
} 

也許不是最漂亮的事情,因爲它會打開一個模態控制器另一個模式的控制器,但它的工作原理。

+0

這將工作正常我的目的。謝謝。 – 2010-08-23 20:01:10