0

I currently set up an app which receives push messages from Amazon SNS (which works fine). On the PHP side, I use a normal JSON-similar payload which goes like this:

'aps' => array(
                    'content-available' => 1,
                    'alert' => array('body' => 'Text with or without Umlaut (ÄÖÜ)'),
                    'badge' => 1,
                    'sound' => 'default'
                )

So my issue is: If I send a notification containing Umlauts (Ä,Ö,Ü), the Push Badge in the upper part show the text properly upon receveing this. However, my app doesn't: It receives < null>. I process messages in a normal didreceveive...

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

So I logged the received userInfo dictionary as the first thing in this method and here I received the :

NSLog(@"userInfo=%@",userInfo);


alert =         {
        body = "<null>";
    };
    badge = 1;
    "content-available" = 1;
    sound = default;

Without umlauts- it works fine! There aren't any questions regarding this and that's why I would appreciate any input right now...

Thanks in advance!

Roman
  • 47
  • 2
  • 9
  • and if your are sending notifications without german umlauts (Umlauts hört sich voll seltsam in Englisch an :D) does that work? Or do you getting the same/other errors? – Krummy Jan 23 '15 at 14:21
  • Hi Krummy, yeah exactly that's the issue - it works 100% without these umlauts! The translation according to dict.cc is "special character". ;) – Roman Jan 23 '15 at 14:33
  • you could try to set the "charset" within the header (there are possibilites for html, php, android and so on.. you may need to google it :D). An example would be – Krummy Jan 23 '15 at 14:42
  • Thanks for the answer- yes the issue was that I use a PHP formula called JSON_ENCODE (I'm not a PHP expert), which uses ASC II ! Your solution didn't solve this, however I'll keep you posted ! – Roman Jan 23 '15 at 14:49
  • You still mus verify that all your statements are "translated" into uft-8. Have a look at my answer below. I hope i can point you at least into the right direction ;) – Krummy Jan 23 '15 at 14:57

1 Answers1

0

Have a look at this article on stackoverflow. Both of the solution i post are there with some comments. Hop it helps you.

Solution 1:

You can define the document type with utf-8 charset (like written in a comment on qour question):

<?php header('Content-Type: application/json; charset=utf-8'); ?>

Make sure that all content is utf_encoded. JSON works only with utf-8!

function encode_items(&$item, $key)
{
    $item = utf8_encode($item);
}
array_walk_recursive($rows, 'encode_items');

Solution 2:

Another solution would be to use htmlentities().

<?php
    $test = array( 'bla' => 'äöü' );
    $test['bla'] = htmlentities( $test['bla'] );

    echo json_encode( $test );
?>
Community
  • 1
  • 1
Krummy
  • 658
  • 15
  • 24
  • Thanks, that was very helpful! To sum it up, I declared all strings which will be sent via apns like this: $push_title = utf8_encode('Title with or without Umlaut ÜÖÄ'); ==> the system itself displays them correctly, I just didn't realize this instantly - I only looked at the console and it prints the pure UTF.... don't let the console make you do more work --! – Roman Jan 23 '15 at 15:39