收到推送通知后显示模式

发布于 2024-09-15 17:06:17 字数 493 浏览 4 评论 0原文

每当收到推送通知时(应用程序运行时),我需要显示通知模式。我的应用程序有一个选项卡栏,我通过将通知模式推到选项卡栏控制器上使其部分工作。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {        
    NotificationViewController *vc = [[NotificationViewController alloc] init];
    [tabBarController presentModalViewController:vc animated:YES];
    [vc release];
}

然而,当已经打开了隐藏选项卡栏控制器的不同模式时,这似乎失败了。确保在收到推送通知时,NotificationViewController 始终显示的最佳方法是什么,即使已经打开了隐藏选项卡栏控制器的模式?

I need to show a notification modal whenever a push notification is received (while the app is running). My app has a tab bar, and I've gotten this to partially work by pushing the notification modal onto the tab bar controller.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {        
    NotificationViewController *vc = [[NotificationViewController alloc] init];
    [tabBarController presentModalViewController:vc animated:YES];
    [vc release];
}

This seems to fail, however, when there is already a different modal open that hides the tab bar controller. What is the best way to make sure that the NotificationViewController always displays when a push notification is received, even if there is already a modal open that is hiding the tab bar controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2024-09-22 17:06:19

您可以做两件事。首先是关闭当前的模态控制器,但这可能会让用户感到困惑。第二件事是这样的:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {      
    UIViewController* currentController = tabBarController;
    if ( [currentController modalViewController] != nil )
          currentController = [currentController modalViewController];

    NotificationViewController *vc = [[NotificationViewController alloc] init];
    [currentController presentModalViewController:vc animated:YES];
    [vc release];
}

可能不是最漂亮的事情,因为它在模态控制器中打开另一个模态控制器,但它有效。

There are two things you can do. First is to dismiss current modal controller, but it could confuse the user. The second thing would be something like that:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {      
    UIViewController* currentController = tabBarController;
    if ( [currentController modalViewController] != nil )
          currentController = [currentController modalViewController];

    NotificationViewController *vc = [[NotificationViewController alloc] init];
    [currentController presentModalViewController:vc animated:YES];
    [vc release];
}

Probably not the prettiest thing to do, as it opens another modal controller in a modal controller, but it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文