I'm working on chat app.I want add support of smiley. I can show smiley direct in iOS using unicode like \
for :-). When I send message using this unicode string than other side is receiving square box like
. How to convert unicode character to nsstring.
I'm using emotion in collection view like bellow
Code :
data = [NSArray arrayWithObjects:@"\ue415",@"\ue056",@"\ue057",@"\ue414",@"\ue405",@"\ue106",@"\ue418",@"\ue417",@"\ue40d",@"\ue40a",@"\ue404",@"\ue105",@"\ue409",@"\ue40e",@"\ue402",@"\ue108",@"\ue403",@"\ue058",@"\ue407",@"\ue401",@"\ue40f",@"\ue40b",@"\ue406",@"\ue413",@"\ue411",@"\ue412",@"\ue410",@"\ue107",@"\ue059",@"\ue416",@"\ue408",@"\ue40c",@"\ue11a",@"\ue10c",@"\ue32c",@"\ue32a",@"\ue32d",@"\ue328",@"\ue32b",@"\ue022",@"\ue023",nil];
CollectionView Delegate Methods
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"EmojiCell";
UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor grayColor];
UILabel *lable = (UILabel *)[cell viewWithTag:100];
lable.text = [data objectAtIndex:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
messageField.text = [NSString stringWithFormat:@"%@%@",messageField.text,[data objectAtIndex:indexPath.row]];
}
Code For Sending A Message
NSString *messageStr = self.messageField.text ;
if([messageStr length] > 0) {
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue: messageStr];
XMPPJID *jid = [XMPPJID jidWithString:chatWithUser];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
[message addChild:body];
[self.xmppStream sendElement:message];
}
Just change symbolCode.
unichar symbolCode = 0xf086;
NSString *chatIcon =[NSString stringWithCharacters:&symbolCode length:1];
Edited for you:
unichar symbolCode = 0xE415;
NSString *smile =[NSString stringWithCharacters:&symbolCode length:1];
NSLog(@"%@",smile);
UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 100, 50)];
lab.text = smile;
[self.view addSubview:lab];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.