scb998 scb998 - 2 years ago 98
Objective-C Question

Extract "alert" text from push notification

I have the following code placed in my app delegate file. In theory, it should be extracting the message from the push notification and displaying it in a

- yet it displays the title and the candle button, and nothing else. Can anybody see where I am going wrong?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
pushText = [userInfo objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"News", "")
otherButtonTitles: nil];
[alert show];

Answer Source

The push payload has the following structure:

    "aps" : {
             "alert" : "Push notification text"

So you need to pull out the "aps" dictionary first and then you can retrieve the value for the "alert" key:

 pushText = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download