Is it possible to retrieve the information from a sent Push Notification using the NSDictionary? (For example, getting the title, message and sound that the alert payload contained).
I also want to send information in the payload (such as a string) for the app to use that isn't related to the title or message. Again, is this possible?
Yes, both is possible!
Referring to getting the desired information, do the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Push notification was received when the app was in the background
// .....
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
// do something with your dictionary
}
}
// .....
return YES;
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
// Push notification received while the app is running
NSLog(@"Received notification: %@", userInfo);
// do something with your dictionary
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With