ios - 收到苹果推送通知时从 Storyboard 打开一个 View Controller

标签 ios objective-c storyboard push-notification

我正在开发一个应用程序,它有一个带有 3 个 View Controller 的 Storyboard和启用推送通知的应用程序。当我收到推送通知并且当我点击通知警报时,它应该从我的 Storyboard中打开第二个 View Controller ,让我显示我的代码。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];

}

然后 Storyboard 加载,这实际上是我的第一个 View Controller ,其中还有一个按钮到第二个 View Controller ,这就是我要加载的 Controller 。这是我的第一个 View Controller 中的代码。
- (void)viewDidLoad
{
   [super viewDidLoad];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationReceived) name:@"pushNotification" object:nil];
}
-(void)pushNotificationReceived{
    NSString * storyboardName = @"DealerMainStoryboard";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
    UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"DealerBuyRequests"];
    [self presentViewController:vc animated:YES completion:nil];
}

因此,当我收到带有此代码的通知时,当我点击通知时应用程序崩溃。

最佳答案

您需要获取一些错误日志,但请检查此内容。

UIViewController * vc = 
       [storyboard instantiateViewControllerWithIdentifier:@"DealerBuyRequests"];

我不认为你想创建一个新的 UIViewController ,除非您真的将 Controller 命名为“ UIViewController ”。

因此,再次检查您要以模态方式呈现的 View 的类名
DealerBuyRequestsViewController * vc = 
       [storyboard instantiateViewControllerWithIdentifier:@"DealerBuyRequests"];

确保 StoryBoard Id此 View Controller 的匹配 DealerBuyRequests否则你会得到错误。

关于ios - 收到苹果推送通知时从 Storyboard 打开一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21837392/

相关文章:

ios - Xcode 5 - 具有恒定背景的滑动切换 View

Objective-C 内存管理 : What is happening when setting a retain property?

java - iOS + appium java 客户端 : Long press TouchAction does not work?

ios - 粘贴到 UISearchController 的 UISearchBar 时启用返回键

objective-c - 与父类(super class)属性名称和协议(protocol)方法名称冲突

iphone - 使用多个 subview 使交叉点透明

ios - tabbar背景图片透明变成白色

ios - Storyboard - UILabel 自动收缩不起作用

objective-c - 将一个 iOS Storyboard 项目包含到另一个项目中?

ios - AIR:第 3 方 iOS native 扩展的链接器错误