我问了几次这个问题,我尝试了几种不同的方法,但没有成功.
我尝试过的最新方法如下:
我包含了我想要显示的ViewController.然后我将此代码放在didReceiveRemoteNotification方法中.
CarFinderViewController *pvc = [[CarFinderViewController alloc] init]; // [self.window.rootViewController presentViewController:pvc animated:YES completion:nil]; [(UINavigationController *)self.window.rootViewController pushViewController:pvc animated:NO];
这没用.我认为我可能遇到的问题是我的初始视图不像许多示例所示的导航控制器.
这是我的故事板的图片>我想发送给用户的VC是汽车发现者(右下角)
有人可以向我解释我可能做错了什么吗?
解决方法
收到远程通知时,您可以使用基本上postNotification
对于像你这样的didReceiveRemoteNotification帖子通知中的exmaple
对于像你这样的didReceiveRemoteNotification帖子通知中的exmaple
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
现在在你的FirstViewController中你可以像这样为这个通知注册FirstViewController
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationReceived) name:@"pushNotification" object:nil];
并在你的方法
-(void)pushNotificationReceived{ CarFinderViewController *pvc = [[CarFinderViewController alloc] init]; [self presentViewController:pvc animated:YES completion:nil]; }
-(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }