iOS:在推送通知中未收到表情符号 - Objective C
iOS: Not getting emoji in Push Notification - Objective C
我在我的应用程序的聊天中实现了表情符号,这在我的应用程序中运行良好。但是当我通过推送通知收到相同的消息时,它显示的是 unicode 而不是表情符号。有人可以帮我吗?
截图如下:
Notification showing Unicode
Message showing emojis
下面是我用来转换表情符号并在我的消息页面中再次显示的代码:
- (NSString *)convertSmiley:(NSString *)type :(NSString *)text {
NSString *emojiValue = @"";
if ([type isEqualToString:@"encode"]) {
NSData *data = [text dataUsingEncoding:NSNonLossyASCIIStringEncoding];
emojiValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
else {
NSData *data2 = [text dataUsingEncoding:NSUTF8StringEncoding];
emojiValue = [[NSString alloc] initWithData:data2 encoding:NSNonLossyASCIIStringEncoding];
}
return emojiValue;
}
在我们的一个项目中,我们使用消息的编码解码,因为从 iOS 发送的笑脸在 Android 中显示不正确,反之亦然,从 Android 发送的笑脸在 iOS.
上显示不正确
所以我们有了方法,对消息进行编码并将其发送到服务器。他们以编码形式保存数据,并将相同的编码数据发送到其他移动端,并在那里进行解码。
But for remote notification,
Notification push from server is shown in default iOS popup on notification center handled by device itself. Our decoding happens only inside of the application and hence your message will appear in encoded form on device.
解决这个问题:
我们要求后端团队先解码发送远程推送消息。
我们在Swift中使用了以下代码来编解码方法:
// Encode strings in UTF-8 format
func encode(_ s: String) -> String {
let variable = s.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!
return variable
}
// Decode strings in UTF-8 format
func decode(_ s: String) -> String? {
let val = s.replace(target: "+", withString: "%20") // + appears in string while encoded from android
let decodedString = val.removingPercentEncoding!
return decodedString
}
我在我的应用程序的聊天中实现了表情符号,这在我的应用程序中运行良好。但是当我通过推送通知收到相同的消息时,它显示的是 unicode 而不是表情符号。有人可以帮我吗?
截图如下:
Notification showing Unicode
Message showing emojis
下面是我用来转换表情符号并在我的消息页面中再次显示的代码:
- (NSString *)convertSmiley:(NSString *)type :(NSString *)text {
NSString *emojiValue = @"";
if ([type isEqualToString:@"encode"]) {
NSData *data = [text dataUsingEncoding:NSNonLossyASCIIStringEncoding];
emojiValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
else {
NSData *data2 = [text dataUsingEncoding:NSUTF8StringEncoding];
emojiValue = [[NSString alloc] initWithData:data2 encoding:NSNonLossyASCIIStringEncoding];
}
return emojiValue;
}
在我们的一个项目中,我们使用消息的编码解码,因为从 iOS 发送的笑脸在 Android 中显示不正确,反之亦然,从 Android 发送的笑脸在 iOS.
上显示不正确所以我们有了方法,对消息进行编码并将其发送到服务器。他们以编码形式保存数据,并将相同的编码数据发送到其他移动端,并在那里进行解码。
But for remote notification,
Notification push from server is shown in default iOS popup on notification center handled by device itself. Our decoding happens only inside of the application and hence your message will appear in encoded form on device.
解决这个问题:
我们要求后端团队先解码发送远程推送消息。
我们在Swift中使用了以下代码来编解码方法:
// Encode strings in UTF-8 format
func encode(_ s: String) -> String {
let variable = s.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!
return variable
}
// Decode strings in UTF-8 format
func decode(_ s: String) -> String? {
let val = s.replace(target: "+", withString: "%20") // + appears in string while encoded from android
let decodedString = val.removingPercentEncoding!
return decodedString
}