zhuang
zhuang

Reputation: 13

How to transcoding emoji in iOS ?

I'm studying Objective-C.When my project need transcoding emoji ,I don't know how to deal with it.

The Requirement are follow:

1.when user send their comment , I should transcoding emoji to a string like unicode or utf-8 cause our server don't store emoji.

2.when user load comment data ,I should transcoding string to a emoji which was System comes (now is iOS 10 which have National flag cost 4 btyes) .And present emoji in device.

Any suggestions?

Upvotes: 0

Views: 178

Answers (1)

Ravi Kiran
Ravi Kiran

Reputation: 185

Before saving the comment to server use the below code

NSData *dataForEmoji = [comment dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *encodevalue = [[NSString alloc]initWithData:dataForEmoji encoding:NSUTF8StringEncoding];

Save the encodedvalue to your server.

When you retrieve use below code before you display

NSString *emojiText = [NSString stringWithCString:[textFromServer cStringUsingEncoding:NSUTF8StringEncoding]
                                  encoding:NSNonLossyASCIIStringEncoding];

Upvotes: 1

Related Questions