iOS empty Firebase Push notification doesn't show up

拈花ヽ惹草 提交于 2019-12-12 05:30:44

问题


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:


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.



来源:https://stackoverflow.com/questions/45223405/ios-empty-firebase-push-notification-doesnt-show-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!