I'm able to send push notifications to my IOS device. But when I click on that notification it just opens the app. No message is shown inside the app.
Code used by me:
if (application.applicationState == UIApplicationStateActive) {
NSString *cancelTitle = @"Close";
NSString *showTitle = @"Show";
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Some title"
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:showTitle, nil];
[alertView show];
[alertView release];
} else {
//Do stuff that you would do if the application was not active
}
But unable to show my message with the help of above code. Above code only works when my app is open that is in foreground state than only this alert gets displayed else not.
Please help.
Thanks.
From the apple documentation
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/Introduction.html
So check if your app has been launched due to a notification and if so display the dialog.
I think there is one easy solution.
If you want to show the alert only when you open the application from the notification then maybe you this is your solution
When application is totally killed get notification code
For more go through this link: Handling Push Notifications when App is Terminated
Handling Push Notifications when App is NOT running (or Totally Killed)
I'm posting this solution as it worked for me.
Go to your AppDelegate.m file.
Step 1: Write this code inside this function:
Step 2:
Insert This full code:
This whole code will work whether app is Active, InActive or Totally Killed. It will give you AlertView for push messages.
The best way to handle things like this is to use deep linking within your APN. That will let you embed data that can then be handled within your app and direct the user to a specific event.
Otherwise, you are limited to using the
ApplicationDidEnterForeground
method from your app delegate. Just put your alertView code in there and anytime your application is brought into the foreground that will run.