从远程通知

时间:2017-09-26 10:09:51

标签: ios objective-c iphone apple-push-notifications

我的iOS应用程序使用Objective C.它收到一个远程通知,当用户点击它时,它会打开一个特定的视图。

此视图在导航选项卡中有一个后退按钮。在正常情况下可以返回到根视图。但是,当我从通知中打开此视图时,无法返回任何视图也无法退出应用程序。

这是我的云杉代码:  1.从AppDelegate.m打开一个特定的视图:

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

UIViewController *viewAnnouncement =[storyboard instantiateViewControllerWithIdentifier:@"Announcement"];

self.window.rootViewController = viewAnnouncement;
[self.window makeKeyAndVisible];
  1. 回到上一个视图的动作函数(在viewClass.m中):

    - (IBAction)onBtnBackClicked:(id)sender {
        [self dismissViewControllerAnimated:YES completion:nil];
     }
    
  2. 我认为问题在于,当我从通知中打开此视图时,没有父视图让它返回。当用户从通知中打开此视图时,是否可以访问根视图或返回上一个打开的应用程序,任何人都可以帮助我

3 个答案:

答案 0 :(得分:0)

编辑:之前的回答没有考虑到你在AppDelegate的事实。也许这个答案更好。

转动[self dismissViewControllerAnimated:YES completion:nil]

进入:

UINavigationController *navigationController = [[UINavigationController alloc] init];
UIViewController *yourPreviousVC = [[UIViewController alloc] init];

    [navigationController pushViewController:yourPreviousVC animated:YES];

如果我错了或者我错过了这个问题,请不要犹豫,纠正我的答案。

答案 1 :(得分:0)

试试这个

Announcement *annouce = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Announcement"];
HomeVC *home = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"HomeVC"];
[((UINavigationController *)self.window.rootViewController) setViewControllers:@[home,annouce] animated:YES];

如果应用已经打开,您想要转到上一页

Announcement *annouce = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Announcement"];
UIViewController *visibleView = ((UINavigationController *)window.rootViewController).visibleViewController;
[((UINavigationController *)self.window.rootViewController) setViewControllers:@[visibleView,annouce] animated:YES];

答案 2 :(得分:0)

我找到了解决方案。我的应用程序有多个视图,我可以从导航列表中查看。当我想回到主视图时,我只是关闭当前视图。

当我点击通知时,会打开一个视图,我不能简单地忽略这个视图,因为它被视为根视图。

我做了什么来解决它,我通过segue将我的视图(公告)连接到主视图,并设置一个标识符(例如:“leaveAnnouncementPage”。然后,在你的类中,只需在后退按钮的函数中调用此函数即可返回主视图:

[self performSegueWithIdentifier:@"leaveAnnouncementPage" sender:self];

这里还有一些有用的链接:

First

Second

谢谢你们的帮助,以及所有最好的

相关问题