iPhone - App still running, receive push notification = change view

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.

Answers


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

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.


Need Your Help

customizing ag-grid to set a max number of selectable rows

angularjs datatable row selection ag-grid

I am trying to customize a data table using ag-grid in my Angular 1.5 based project. The customization is that the user is allowed to select a maximum number of rows in the table, for example, the

I am facing "Your login attempt was not successful" Please try again. error while implementing custom membership

c# asp.net custom-membershipprovider multi-database

My requirement of application is single application & multiple databases for each client. So I implemented custom membership to achieve this. First I check user belongs to which Client the acco...