iPhone - 应用程序仍在运行,接收推送通知 = 更改视图

发布于 2024-09-11 22:09:41 字数 493 浏览 3 评论 0原文

我试图在应用程序仍在运行时收到推送通知后更改视图。我尝试在 AppDelegate.m 中使用它,

-(void)application:(UIApplication *)application didRecieveNotification:(NSDictionary *)userInfo
{ 
   TestClass *aTestClassViewController = [[TestClass alloc]initWithNibName:@"TestClass" bundle:nil];
   [self presentModalViewController:aTestClassViewController animated:YES];
   [aTestClassViewController release];
}

但它不起作用。我什至无法再次启动该应用程序。所以我猜这是错误的做法。

大家有什么想法吗?我将不胜感激。

I'm trying to change view upon receive a push notification while the app is still running. I tried using this in the AppDelegate.m

-(void)application:(UIApplication *)application didRecieveNotification:(NSDictionary *)userInfo
{ 
   TestClass *aTestClassViewController = [[TestClass alloc]initWithNibName:@"TestClass" bundle:nil];
   [self presentModalViewController:aTestClassViewController animated:YES];
   [aTestClassViewController release];
}

But it didn't work. I can't even start up the app again. so I'm guessing this is the wrong way to do it.

Any idea guys? I would appreciate it.

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

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

发布评论

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

评论(2

小耗子 2024-09-18 22:09:41

已解决***
我是这样做的->
我首先显示了一个警报视图(无论如何我都需要)
然后使用了方法

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    TestClass *aSelectionScreenViewController = [[TestClass alloc] initWithNibName:@"TestClass" bundle:nil];
    [viewController presentModalViewController:aSelectionScreenViewController animated: YES]; 
    [aSelectionScreenViewController release];   }

Solved***
I did it this way ->
I showed an alert view first (Which i needed anyways)
then used the method of

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    TestClass *aSelectionScreenViewController = [[TestClass alloc] initWithNibName:@"TestClass" bundle:nil];
    [viewController presentModalViewController:aSelectionScreenViewController animated: YES]; 
    [aSelectionScreenViewController release];   }
白衬杉格子梦 2024-09-18 22:09:41

我们缺少一些有关您的应用程序的上下文,但您的基本问题是接收通知的是应用程序委托对象,而不是视图控制器。这就是为什么你不能只做 [selfpresentModalViewController:someViewController];

我认为您自己的答案中的片段可以满足您的需求:您的应用程序委托(大概)有一个“viewController”成员,它是应用程序的根视图控制器。您需要推动 viewController 对象执行您需要的任何操作。在我现在正在查看的应用程序中,我在应用程序委托中有一个 tabBarController 成员,并且在收到通知时显示警报视图和/或更改选定的选项卡索引。

我会让您的应用程序委托调用一个函数当消息传入时,在主视图控制器上,并让该函数显示警报视图,然后执行所需的任何状态更改以使主视图控制器反映收到的通知。

We're missing some context about your application, but your basic problem is that it's the application delegate object which is receiving the notification, not a view controller. That's why you can't just do [self presentModalViewController:someViewController];

I think it's the snippet from your own answer that gives what you need: your app delegate (presumably) has a 'viewController' member, which is the root view controller for the application. It is that viewController object you need to prod into doing whatever it is you need. In the app I'm looking at right now, I have a tabBarController member in the app delegate, and I show an alert view and/or change the selected tab index when a notification comes in.

I would have your app delegate call a function on your main view controller when a message comes in, and have that function show the alert view, then do whatever state changes you need to do to make the main view controller reflect the received notification.

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