iOS empty Firebase Push notification doesn't s

2019-08-22 10:15发布

I'm having a weird problem with Firebase notification on iOS. It works perfectly but the only problem is if I keep the 'body' parameter on the server empty it does play notification sound on the app but doesn't show anything. Same thing displays notification on Android. Is it some kind of Apple security that I'm running into? if I only add an empty space " " in 'body' it would show up but nothing without it. If any body could suggest me anything please. my server side code

 $msg = array
          (
        'title'     => '',
        'body'  => ' ',
        'click_action' => '.InstagramLoader',
      'icon'    => 'myicon',/*Default Icon*/
         'sound' => 'mySound'/*Default sound*/
          );

        $data = array(
'text' => $title,
'img_url' => $img_url
);


    $fields = array
            (
                'to'        => $registrationIds,
                'notification'  => $msg,
                'data' => $data
            );




    $headers = array
            (
                'Authorization: key=' . API_ACCESS_KEY,
                'Content-Type: application/json'
            );
#Send Reponse To FireBase Server    
        $ch = curl_init();
        curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
        curl_setopt( $ch,CURLOPT_POST, true );
        curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
        curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
        curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
        $result = curl_exec($ch );
        curl_close( $ch );

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-22 11:15

Yes that's an iOS thing, why show an empty push notification right? You could use isNaN() in your server side code and check for an empty body and set it to a default value.

查看更多
登录 后发表回答