gpt4 book ai didi

ios - 收到推送消息时从 Appdelegate 导航

转载 作者:行者123 更新时间:2023-11-28 22:02:06 25 4
gpt4 key购买 nike

目前我的方法是这样的

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSString *screenNo =[userInfo objectForKey:@"screen"];

}

基于 screenNo 我想导航到不同的 View Controller 。但我不能像下面给出的大多数答案那样做。

原因是我的 Root View 不是导航控件,所以我无法继续。它会使应用程序崩溃。

当推送消息到达时 didReceiveRemoteNotification 被调用,我也可以看到消息的内容。但它不会使用此处显示的方法进行导航。

    [self.window makeKeyAndVisible];
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"galleryViewController2"];
[(UINavigationController *)self.window.rootViewController pushViewController:vc animated:YES];

这是异常(exception)

2014-07-21 18:06:53.709 Proitzen Rest[993:60b] -[RESTSecondViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14e26270
2014-07-21 18:06:53.712 Proitzen Rest[993:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RESTSecondViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14e26270'
*** First throw call stack:
(0x2f480fd3 0x3a021ccf 0x2f484967 0x2f483253 0x2f3d27b8 0xff93b 0x31eb3b29 0x31eb37fb 0x31dbb05f 0x31e6d377 0x31d1c6f5 0x31c9555b 0x2f44c2a5 0x2f449c49 0x2f449f8b 0x2f3b4f0f 0x2f3b4cf3 0x342da663 0x31d0016d 0x157e69 0x3a52eab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

提前感谢您抽出时间。

最佳答案

你试过这样的事情吗?

UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"galleryViewController2"];
self.window.rootViewController = vc;

您可以用新 Controller 替换当前 Controller ,而不是推送您的新 Controller (它会崩溃,因为要推送您需要一个导航 Controller )。

请注意,您无法弹出到原始 Controller (如果您需要返回,则需要导航)

关于ios - 收到推送消息时从 Appdelegate 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24864909/

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