gpt4 book ai didi

iphone - 从 didReceiveRemoteNotification 打开 View

转载 作者:可可西里 更新时间:2023-11-01 17:09:10 25 4
gpt4 key购买 nike

这个问题我被问过几次,我尝试了几种不同的方法,但都没有成功。

我试过的最新方法如​​下:我包括了我想展示的 ViewController。然后,我将此代码放入 didReceiveRemoteNotification 方法中。

    CarFinderViewController *pvc = [[CarFinderViewController alloc] init];
// [self.window.rootViewController presentViewController:pvc animated:YES completion:nil];
[(UINavigationController *)self.window.rootViewController pushViewController:pvc animated:NO];

这没有用。我认为我可能遇到的问题是我的初始 View 不是像许多示例所示的导航 Controller 。

enter image description here

这是我的 Storyboard的图片> 我要将用户发送到的 VC 是汽车查找器(右下角)

有人可以向我解释我可能做错了什么吗?

最佳答案

当您收到远程通知时,您基本上可以使用 postNotification例如在你的 didReceiveRemoteNotification 中发布这样的通知

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

关于iphone - 从 didReceiveRemoteNotification 打开 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15139744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com