我在openfire聊天应用服务器中发送表情符号时发现此错误。请建议如何解决。
错误Domain = GCDAsyncSocketErrorDomain Code = 7" Socket由远程关闭 同行" UserInfo = {NSLocalizedDescription =由远程对等方关闭的套接字}
答案 0 :(得分:1)
使用NSNonLossyASCIIStringEncoding
和NSUTF8StringEncoding
NSString *messageStr = [NSString stringWithUTF8String:[textview.text UTF8String]];
// encode message
NSData *msgData = [textview dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodMsg = [[[NSString alloc] initWithData:msgData encoding:NSUTF8StringEncoding] autorelease];
注意:如果您的客户端应用程序将表情符号格式化为\ ue415,您可以使用以下内容对其进行转换:
- (NSString *) substituteEmoticons {
NSString *res = [self stringByReplacingOccurrencesOfString:@"\ue415" withString:@":)"];
res = [res stringByReplacingOccurrencesOfString:@"\ue403" withString:@":("];
res = [res stringByReplacingOccurrencesOfString:@"\ue405" withString:@";-)"];
res = [res stringByReplacingOccurrencesOfString:@"\ue418" withString:@":-x"];
.....
return res;
}