immobiliare / ApnsPHP

ApnsPHP: Apple Push Notification & Feedback Provider
BSD 3-Clause "New" or "Revised" License
1.44k stars 452 forks source link

Fix to work with cyrillic letters #33

Closed pilot34 closed 11 years ago

pilot34 commented 11 years ago

I had problem on one server with messages in push, when one symbol is more than one byte. There was error xxx bytes instead of yyy bytes. It was fixed with this patch.

It is very strange, I think on another server ApnsPHP was working without patches. Can it be because of default server encoding?

I'm obj-c developer, not good in php, so I'm not very sure, that my fix is good for all cases, but I think, that mb_strlen with '8bit' is better to right counting of length in bytes. Isn't it?

ghost commented 11 years ago

$nLen = mb_strlen($aMessage['BINARY_NOTIFICATION'], '8bit'); you can't use 8bit encoding for russian because you should send request in json and json require an utf-8.

and I have no troubles with russian (except length, of course), vietnam, chinese and other languages :)

pilot34 commented 11 years ago

you can't use 8bit encoding for russian because you should send request in json and json require an utf-8.

So, I'm using 8bit only to count right length of string in bytes. I don't change string, that is sending to server.

ghost commented 11 years ago

hm, you are correct, sorry.

ghost commented 11 years ago

but it's why Duccio are using simple strlen() -- it works only with 8bit encoding and it calculate bytes.

pilot34 commented 11 years ago

Yes, but on my server settings there was wrong length with strlen(), I have no idea why...

ghost commented 11 years ago

Here is a solution: https://github.com/duccio/ApnsPHP/issues/27

pilot34 commented 11 years ago

hshhhhh, thank you! I haven't found it