I have my iPhone application implemented with a push notification. I successfully implemented the push notification basically. When I tapped the push notification message, the message will display on the message label on the ViewController. However, when I open the icon(Application), it didn't return any notification. I need to display the push notification not only in tapping the push notification but It should work if the iOS user just opens the app too.
here is my code.
AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification: (NSDictionary*)userInfo{
NSString *messageAlert = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
NSLog(@"Received Push Message: %@", messageAlert );
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotification" object:messageAlert];
on my ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:@"MyNotification" object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *_string = note.object;
messages.text = _string; //message
}];
}
}
It will display the notification though when the notification i clicked. But when i open the app, the notification must display the message too. How to do that? please help me.