Here is my problem : I'm currently developping an app including an instant chat (using FCM). Every thing works except when i try to send special characters like "é" or emojis. The push notification received contains the good string but when the discussion is saved on the server and then reloaded, I can't read them and get UTF8 text like "u00ea" for "ê". I don't really know a lot about encoding etc. but if you guys could help I would be very happy !
Here is the code i use to send a message :
func sendMessage(_ completion: @escaping (_ response: String) -> ()) {
DispatchQueue.global(qos: .userInitiated).async { () -> Void in
let urlString = //Server adress
let url = URL(string: urlString)
var request = URLRequest(url: url!)
let set = CharacterSet()
request.httpMethod = "POST"
let postString = "Message=" + /*String text to send*/
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
})
task.resume()
}
}
Thanks a lot !
PS : I'm new to asking to stackoverflow so don't hesitate to ask for more details
Edit as asked by Rob :
I sent the message "test é è".
The other phone received "test é è" via push notification.
When one phone loads discussion from the server where its stored the answer from the server is.
[{"content":"test u00e9 u00e8","sender":"103","timestamp":"1475491191"}]
Also I'm not coding the server, but the guy who is is also making an android app which works really fine with special characters.
Edit #2 : I also try this code
var request = URLRequest(url: url!)
let set = CharacterSet()
request.httpMethod = "POST"
let postString = "Message=" + self.message.addingPercentEncoding(withAllowedCharacters: set)!
let bytesArray = UTF8Encoding.decode(postString)
request.httpBody = Data(bytes: UnsafePointer<UInt8>(bytesArray), count: bytesArray.count)
It does not make any difference.
Thanks a lot for your help guys.