【问题标题】:IONIC 2: How to add the custom icon and image in the push notification using PHP and firebaseIONIC 2:如何使用 PHP 和 firebase 在推送通知中添加自定义图标和图像
【发布时间】:2018-03-04 17:25:49
【问题描述】:

这是我用于向 ionic 应用发送推送通知的 PHP 代码:

$token = json_encode(array("token"=>$token_array)) ; 

$title = "This is Title";
$body = "Test Body Message";

$notification = array(
                   'title' =>$title , 
                   'text' => $body,
                   'vibrate'=>1,
                   "icon"=> "appicon",
                   'sound' => 'mySound'
               );

$arrayToSend = array(
                  'registration_ids'=>$token_array, 
                  'notification' => $notification,
                  'priority'=>'high'
               );

$json = json_encode($arrayToSend);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key= MYKEY'; 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);       

$response = curl_exec($ch);    
curl_close($ch);

我已经包含了图标参数的在线链接,但它仍然不起作用。请提出我哪里错了..提前谢谢。

【问题讨论】:

  • 你让它工作了吗?
  • 这一切都对我不起作用。请帮助我更正代码。
  • 你试过icon => 'myicon'吗?
  • 感谢您的帮助,但您能告诉我与 myicon 相关的含义是默认值还是什么?

标签: php angular typescript firebase push-notification


【解决方案1】:

您可以尝试以下对我有用的代码。它在除Samsung 之外的大多数设备上显示图标。我现在正在尝试解决这个问题。

$message_for_push = array(
        "data" => array(
            "title" => "New Content Published!",
            "body"  => $message['title'],
            "icon"  => "myicon",
            "color"  => "#e81010",
            'sound' => 'mySound',
        ),

        "registration_ids" =>  $registrationIds ///unique device ids json encoded array
    );
$message_for_push = json_encode($message_for_push);
$curl = curl_init();

curl_setopt_array($curl, array(
        CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_SSL_VERIFYHOST=>0,
        CURLOPT_SSL_VERIFYPEER=>0,
        CURLOPT_POSTFIELDS => $message_for_push,
        CURLOPT_HTTPHEADER => array(
            "authorization: key=AAAArIw35_I:AUTHORIZATION_KEY_HERE",
            "cache-control: no-cache",
            "content-type: application/json"
        ),
    ));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

希望对你有帮助..:)

【讨论】:

  • 谢谢,@masud_moni 颜色已更改,但我的应用图标没有出现。
  • 我的通知图标也有问题,我尝试了很多方法但无法在三星上运行,我可以在其他设备上获取图标。让我们看看会发生什么..:)
  • 好的,但我什至没有使用我的一加设备,但我会检查一下,谢谢 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-22
  • 2020-08-14
  • 2015-08-19
  • 1970-01-01
  • 1970-01-01
  • 2017-11-17
相关资源
最近更新 更多