2014-12-03 111 views
0

我已經使用故事板。該應用程序是基於標籤欄控制器。 。從didReceiveRemoteNotification加載故事板視圖控制器

當點擊推送通知,我想從故事板打開特定的「通知事件」視圖控制器」 我不知道什麼樣的代碼進入didReceiveRemoteNotification

這裏我的代碼是:

NSString *notification = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"]; 

Dashboard *ds = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Dashboard"] ; 
NotificationTable *nt = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"NotificationBoard"] ; 

UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"NotificationBoardTable" 
                  source:ds 
                 destination:nt 
                performHandler:^{ 
                }]; 

[ds performSegueWithIdentifier:@"NotificationBoardTable" sender:ds]; 
+0

的朋友,可以在任何一請幫助我嗎? – 2014-12-03 09:46:31

+0

你的意思是你想在接收遠程通知後改變ViewController嗎? – Horst 2014-12-03 10:46:27

+0

ya exaclty dude。 @horst – 2014-12-03 10:49:31

回答

1

讓我們來看看,如果這是你想要什麼:

[[NSNotificationCenter defaultCenter] postNotificationName:kReceiveNotification object:nil userInfo:YOUR_DATA_PASSING]; 

然後接受它在你的自定義選項卡視圖控制器:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(YOUR_HANDLE_METHOD:) name:kReceiveNotification object:nil]; 

重新分配時,不要忘記刪除觀察者:

[[NSNotificationCenter defaultCenter] removeObserver:self]; 

最後在方法:

[self setSelectedIndex:xxx];//If you want to switch tab 
+0

好吧,我已經嘗試過。但應用程序不在後臺運行。 如何在發出遠程通知時發佈和處理通知。 ,因爲當通知發出時,「didReceiveRemoteNotification」不再被調用。 – 2014-12-03 11:14:46

+0

如果您通過點擊通知啓動的應用程序,你需要處理它 - (BOOL)申請:(UIApplication的*)應用程序didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions { 的NSDictionary * USERINFO = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]。如果(userInfo == NULL) NSLog(@「didFinishLaunchingWithOptions user startup userinfo:%@」,userInfo); (@「didFinishLaunchingWithOptions notification startup userinfo:%@」,userInfo);}} } } – Horst 2014-12-04 03:59:44

相關問題