Reputation: 1479
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
Thanks
Upvotes: 10
Views: 1973
Reputation: 137
In swift :
Encoding : -
let messageData = chatTextView.text.dataUsingEncoding(NSNonLossyASCIIStringEncoding)
let finalMessage = String(data: messageData!, encoding: NSUTF8StringEncoding)
Decoding : -
let data : NSData = str.dataUsingEncoding(NSUTF8StringEncoding)!
let message = String(data: data, encoding: NSNonLossyASCIIStringEncoding)
Upvotes: 0
Reputation: 2294
NSString *string = @"This is \u00B7";
Instead of \u00B7 add your unicode value. Its working solution.
Upvotes: 9