2015-04-22 67 views
0
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    if (applicationIsActive) { 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bildirim" 
                  message:[NSString stringWithFormat:@"%@ ",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]] 
                  delegate:self cancelButtonTitle:@"Ok" 
                otherButtonTitles:nil]; 
     [alertView show]; 

     UIViewController *vc = self.window.rootViewController; 
     AnotherViewController *Anothervc = [Anothervc.storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController "]; 

     [vc presentViewController:Anothervc animated:YES completion:nil]; 
    } 
} 
+0

在'AnotherViewController * Anothervc = [Anothervc.storyboard instantiateViewControllerWithIdentifier:@「AnotherViewController」];'這行 – Akhilrajtr

+0

嘗試'vc.storyboard'而不是'Anothervc.storyboard'但是我想打開特定視圖例如:另一個視圖時我點擊通知在我的Xcode也即時通訊使用xib不是主要故事板 – Riddhi

+0

您使用故事板或xibs在您的項目 – Vidhyanand

回答

0

修改如下代碼..!

UIViewController *vc = self.window.rootViewController; 
AnotherViewController *Anothervc = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"AnotherViewController"];                  
[vc presentViewController:Anothervc animated:YES completion:nil]; 

希望它可以幫助你..!

+0

謝謝。 。它幫助我解決我的問題。 。其工作,因爲我想要通知其特定觀點。 。但是,如果我打開沒有通知它打開另一個視圖控制器。 。那個時候我想打開我的視圖控制器而不是另一個視圖控制器。 。 plz幫我解決了這個問題 – Riddhi

+0

將第一行代碼保存在AppDelegate的didFinishLaunchOptions中。如果推送通知未被觸發,那麼didFinish將加載您的基本視圖。否則,如果啓用它將觸發didReceiveRemoteNotification方法並加載另一個視圖...! – Vidhyanand

0

您可以通過以下代碼獲取任何storyboard的對象。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 

現在控制器與你的故事板對象的幫助。

AnotherViewController *Anothervc = [storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController"]; 

[self presentViewController:Anothervc animated:YES completion:nil]; 
+0

讓我知道你是否有問題 –

0

您並未將「AnotherViewController」添加到MainStoryboard中。 設法得到MainStoryboard的對象像下面

UIStoryboard *sb= [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 

然後修改

AnotherViewController *Anothervc = [Anothervc.storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController"]; 

AnotherViewController *Anothervc = [sb instantiateViewControllerWithIdentifier:@"AnotherViewController "]; 

現在目前它

[self presentViewController:Anothervc animated:YES completion:nil]; 
0

如果您正在使用XIB如果您使用的廈門國際銀行的

UINavigationController *navController = (UINavigationController *)self.window.rootViewController; 
AnotherViewController *anothervc = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil]; 
[navController.visibleViewController.navigationController pushViewController: Anothervc animated:YES]; 

//StoryBoards..Main是連環畫的名字試試這個,

UIViewController *vc = self.window.rootViewController; 

AnotherViewController *anothervc = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil]; 
[vc presentViewController:anothervc animated:YES completion:nil]; 
0

UIViewController * vc = self.window.rootViewController;

AnotherViewController * Anothervc = [storyboard instantiateViewControllerWithIdentifier:@「AnotherViewController」];

[self presentViewController:Anothervc animated:YES completion:nil];