2015-12-24 126 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