2011-10-24 34 views
0

我的應用程序委託有一個RootViewController * viewController;並且該應用程序以此視圖啓動。didReceiveRemoteNotification和模態視圖

從這裏開始,當用戶導航到應用程序中的不同功能時,我將繼續呈現模態視圖(最多3個級別)。

我已經設置了應用程序以接收推送通知,並且我在應用程序委託內部有didReceiveRemoteNotification來檢索有效內容。

現在的問題:

  1. 當收到推送通知,我怎麼能知道用戶目前在該模式的看法?
  2. 如何關閉所有模態視圖以返回到RootViewController?我可以在應用程序代理中實際執行此操作嗎?

回答

1

有沒有通用的內置方式來做到這一點。最好的解決方案可能是將一個屬性添加到您的應用程序委託中,以便存儲它。

@property (nonatomic, retain) UIViewController *currentModalViewController; 

當目前模式視圖控制器,這樣做:

#import "MyAppDelegate.h" 

// .... 
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate; 
appDelegate.currentModalViewController = vc; 
[self presentModalViewController:vc animated:YES]; 

您還需要確保你失去了參考解僱時:

[self dismissModalViewControllerAimated:YES]; 
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate; 
appDelegate.currentModalViewController = nil; 

然後在您的應用程序委託,你有一切你需要的,以消除當前的模態視圖控制器,並檢查目前是否有一個模態視圖控制器。