我正在开发一个应用程序,它有一个带有 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/