Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 retrieve information from a sent Push Notification using the NSDictionary

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?

like image 331
Nick Avatar asked Feb 04 '26 04:02

Nick


1 Answers

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
}
like image 158
tilo Avatar answered Feb 05 '26 20:02

tilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!