-3

How to make formatting of received remote push notification. I am receiving a remote notification which is in JSON format.

When I receive remote notification it shows me same data which is in JSON format. But I want to make some formatting of this JSON data and show remote notification in some formatted text. So is it possible to make formatting of received push notification.Which is in user understandable form.

When I receive push notification it shows me

alert = "{\"messsage\":\"what to do when boarded \",\"chatBox\":\"130701.130693\",\"sender_id\":\"130701\",\"sender_name\":\"reg41\",\"sender_image_url\":\"http:\\/\\/www.playmit.com\\/images\\/user_profile_images\\/\",\"receiver_id\":\"130693\",\"type\":\"chat\"}";
    };

this data in notification bar. Which is in json format. But I want to format this push notification and show only message in notification bar whenever user receives push notification.

So if anybody knows solution please help me thank you.

Thank you.

Pradumna Patil
  • 2,180
  • 3
  • 17
  • 46

1 Answers1

0

EDIT :

My answer is a duplicate, sorry for that :

Converting NSString to NSDictionary / JSON

You can extract the message from your json as follows ( I suppose the variable alert to be an NSString ) :

alert = "{\"messsage\":\"what to do when boarded \",\"chatBox\":\"130701.130693\",\"sender_id\":\"130701\",\"sender_name\":\"reg41\",\"sender_image_url\":\"http:\\/\\/www.playmit.com\\/images\\/user_profile_images\\/\",\"receiver_id\":\"130693\",\"type\":\"chat\"}";
    };
NSData *jsonData = [alert dataUsingEncoding:NSUTF8StringEncoding];
id formattedJson = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
NSString *message = [formattedJson objectForKey:@"message"];

NSLog(@"message : %@", message) should then return :

what to do when boarded

Hope it helps.

Community
  • 1
  • 1
Randy
  • 4,335
  • 3
  • 30
  • 64
  • This will give me my message but how should I show this message in my notification bar instead of complete json data received in push notification. – Pradumna Patil Jun 10 '15 at 10:42
  • @PradumnaPatil did you get a solution for this? – Ganesh Kumar Jun 06 '16 at 12:11
  • yes we can not handle the push notification contents if we are using tha APNS so if you want to receive only the message in the push notification then you need to change your json response and just send the message string in "message" keyword and send the rest of the contents with some other keyword Hope it helps ..... – Pradumna Patil Jun 06 '16 at 14:22