代码无法执行Xcode

时间:2015-12-24 10:18:13

标签: ios objective-c 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];

}


}

如果需要更多信息,请说明。

提前致谢, 干杯

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

尝试这个..它应该有用。