问题描述
我在 iOS 上遇到 Firebase 通知的奇怪问题.它运行良好,但唯一的问题是,如果我将服务器上的body"参数保留为空,它会在应用程序上播放通知声音但不显示任何内容.同样的事情在 Android 上显示通知.这是我遇到的某种 Apple 安全性吗?如果我只在body"中添加一个空格",它会显示出来,但没有它就什么都没有.如果有任何机构可以向我提出任何建议.我的服务器端代码
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 );
推荐答案
是的,这是 iOS 的事情,为什么要显示空推送通知呢?您可以在服务器端代码中使用 isNaN() 并检查空主体并将其设置为默认值.
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 推送通知未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!