【问题标题】:open a viewcontroller from storyboard when receive apple pushnotification收到苹果推送通知时从情节提要打开一个视图控制器
【发布时间】:2014-02-17 19:12:59
【问题描述】:

我正在开发一个应用程序,该应用程序的情节提要具有 3 个视图控制器和启用推送通知的应用程序。当我收到推送通知并且当我点击通知警报时,它应该从我的故事板中打开第二个视图控制器,让我显示我的代码。

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

}

然后加载故事板,这实际上是我的第一个视图控制器,其中还有一个按钮到第二个视图控制器,这就是我要加载的控制器。这是我的第一个视图控制器中的代码。

- (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];
}

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

【问题讨论】:

  • 你的问题在哪里?
  • 应用程序在收到 pushnotification 并且我点击通知时崩溃并显示此代码。
  • 你的错误日志是什么?
  • 我在临时生产 ipa 文件中检查它,那么我怎样才能得到错误日志呢?
  • 也许在控制台上?

标签: ios objective-c storyboard push-notification


【解决方案1】:

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

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

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

所以再次检查你想以模态方式呈现的视图的类名

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

确保此视图控制器的StoryBoard IdDealerBuyRequests 匹配,否则会出错。

【讨论】:

    猜你喜欢
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 2023-04-10
    • 2017-08-13
    相关资源
    最近更新 更多