我在 openfire 聊天应用程序服务器中发送表情符号时发现了这个错误。请建议如何解决它。
Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}
最佳答案
使用 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;
}
关于ios - openfire 聊天服务器在发送表情符号时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37029565/