K.Honda
K.Honda

Reputation: 3106

Push notification to view iPhone

I have got push notification working but the next thing I want to do is to open a relevant view when clicking on the notification.

In my appDelegate.m in didFinishLaunchingWithOptions, I have the following:

NSString *params=[[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"alertType"];

if ([params length] > 0 ) {//app launch when VIEW button of push notification clicked

    if (params == @"sc") {

         Alerts *alerts = [[Alerts alloc] initWithNibName:@"Alerts" bundle:nil];
         [[self navigationController] pushViewController:Alerts animated:YES];
         [Alerts release];
    } else {

    }
}

However, in this line: [[self navigationController] pushViewController:Alerts animated:YES];, a warning comes up saying Method '-navigationController' not found (return type defaults to 'id').

How can I rectify this warning and am I right in trying to push the relevant view in didFinishLaunchingWithOptions?

Thanks.

Upvotes: 1

Views: 1086

Answers (2)

You have to add any navigation Controller to your window from the appdelegate method after setting the naviagationcontroller property.

[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

You can then push the view as you required.

Upvotes: 2

Cyrille
Cyrille

Reputation: 25144

Your navigationController may not be declared as a @property, so you can't use [self navigationController]. Just try self.navigationController, or even just navigationController, if that's its name in your .h.

Also, please don't compare strings with ==. You have to do if ([params isEqualToString:@"sc"]). That compares the contents instead of the address of your string.

Upvotes: 1

Related Questions