scb998 scb998 - 6 months ago 12
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

UIAlertview
- 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", "")
message:pushText
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
}

Answer

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"];
Comments