Handling remote push notification formatting

420 views Asked by At

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.

1

There are 1 answers

3
Randy On

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.