2015-12-24 77 views
0

我知道這是一個有點奇怪,但我已經寫了這個代碼,當用戶點擊一個推送通知,會啓動特定的視圖控制器。當我在設備上運行代碼時,代碼完美運行,但第二次從Xcode中拔出設備並再次運行,代碼不會執行,並且當我單擊推送通知時,視圖控制器無法打開。代碼不能執行的Xcode

下面是代碼我有,如果需要更多信息,請這麼說,我Appdelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
[PFPush handlePush:userInfo]; 

NSDictionary *apsInfo = [userInfo objectForKey:@"aps"]; 

if(apsInfo) { 
    //there is some pending push notification, so do something 
    //in your case, show the desired viewController in this if block 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" 
                 message:[NSString stringWithFormat:@"%@ ",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]] 
                 delegate:self cancelButtonTitle:@"Done" 
               otherButtonTitles:nil]; 
    [alertView show]; 

    UIViewController *vc = self.window.rootViewController; 
    NotificationViewController *pvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"Alerts"]; 

    [vc presentViewController:pvc animated:YES completion:nil]; 

} 


} 

打開我的視圖控制器。

在此先感謝, 乾杯

回答

0
UIStoryboard *storyboard; 
     storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
     self.window.rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"Alerts"]; 
     [self.window makeKeyAndVisible]; 

試試這個..它應該工作。

+0

好了,事實證明,它的作品,如果應用程序仍然在後臺還活着,但是當我從背景中刪除應用程序,然後在視圖控制器不啓動。了... – Rayyan

0
UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:@"myStoryBoardName" bundle:nil]; 
    NotificationViewController *pvc = [mystoryboard instantiateViewControllerWithIdentifier:@"Alerts"]; 
[self presentViewController:pvc animated:YES completion:nil]; 
+0

我似乎得到錯誤「屬性'navigationController'找不到對象的類型AppDelegate – Rayyan

+0

感謝您的評論我會嘗試現在的代碼,雖然我建議你改變自我[pvc presentViewController:pic animated:YES完成:零]; – Rayyan

+0

我已經編輯u能給予綠色對勾 – vaibby