Push notification to view iPhone
I have got push notification working but the next t开发者_高级运维hing 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.
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.
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.
精彩评论