iOS空的Firebase推送通知不显示 [英] iOS empty Firebase Push notification doesn't show up

查看:231
本文介绍了iOS空的Firebase推送通知不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS上遇到了一个有关Firebase通知的奇怪问题。它完美的工作,但唯一的问题是,如果我保持服务器上的身体参数为空,它会播放应用程序中的通知声音,但不显示任何内容。同样的东西在Android上显示通知。我遇到了某种苹果安全吗?如果我只在body中添加一个空的空格,那么它将显示出来,但没有它。如果任何机构可以建议我什么请。
我的服务器端代码

  $ msg =数组

'title'=> '',
'body'=>'',
'click_action'=>'.InstagramLoader',
'icon'=>'myicon',/ * Default Icon * /
'sound'=>'mySound'/ *默认声音* /
);

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


$ fields = array

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



$ b $ headers =数组

'授权:key ='。API_ACCESS_KEY,
'Content-Type :application / json'
);
#Send响应到FireBase服务器
$ 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);


解决方案

是的,这是一个iOS的事情,为什么显示一个空的推通知权?您可以在您的服务器端代码中使用isNaN(),并检查一个空的主体并将其设置为默认值。

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 );

解决方案

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.

这篇关于iOS空的Firebase推送通知不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆