iphone – 从didReceiveRemoteNotification打开视图
发布时间:2020-12-14 17:12:09 所属栏目:百科 来源:网络整理
导读:我问了几次这个问题,我尝试了几种不同的方法,但没有成功. 我尝试过的最新方法如??下: 我包含了我想要显示的ViewController.然后我将此代码放在didReceiveRemoteNotification方法中. CarFinderViewController *pvc = [[CarFinderViewController alloc] init]
我问了几次这个问题,我尝试了几种不同的方法,但没有成功.
我尝试过的最新方法如??下: 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 [[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]; } 不要忘记在dealloc方法中删除观察者的通知 -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |