sailendra k. sailendra k. - 1 year ago 84
Objective-C Question

How to encode emoji while sending to server (Ruby on Rails)?

While I am sending the emoji to server "\ud83d\ude0e" (emoji unicode) in the given format, the server could not understand the code and while sending push notification from server to device, the notification is not coming.

I have used :

NSData *data = [self.activeTextField.text dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

to encode the message(emoji) while sending and used:

NSData *data = [strReceivedMsg dataUsingEncoding:NSUTF8StringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];

while receiving the messages.

Please suggest how to resolve this issue


Answer Source
NSString *string = @"This is \u00B7";

Instead of \u00B7 add your unicode value. Its working solution.