【问题标题】:content or data limit for Android push notification (GCM)Android 推送通知 (GCM) 的内容或数据限制
【发布时间】:2015-04-27 05:25:17
【问题描述】:

使用 php.ini 的 android 推送通知 GCM 是否有任何数据限制。我通过这段代码传递了数据(消息)。

 $url = 'https://android.googleapis.com/gcm/send';
    $fields = array (
    registration_ids' => $registatoin_ids,
    data => $message,
        );
     $headers = array(
     Authorization: key= . GOOGLE_API_KEY,
     Content-Type: application/json
      );
     // Open connection
    if(!function_exists('curl_init')) 
     echo "CURL not installed";
    else
     $ch = curl_init();
    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
     die('Curl failed: ' . curl_error($ch));
     }
    // Close connection
    curl_close($ch);
    $obj = json_decode($result);
    if($obj->{'success'})
         {
           echo "Message Sent Successfully";
         }
         else{
          echo "Sending Error : " . $result;
         }

如果 $message 包含超过 3000 个字符,那么我不会收到任何通知。假设如果 $message 包含少于 1000 个字符,我会收到通知。

提前致谢。

【问题讨论】:

  • 通知是一小段信息。使用 GCM,最多可以在通知中发送 4kb 的有效负载。
  • 所以,如果我们发送超过 4 kb 的有效载荷,它将无法正常工作。

标签: php android push-notification google-cloud-messaging


【解决方案1】:

是的,它的有效负载限制为 4096 字节。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-02-13
  • 2013-02-07
  • 1970-01-01
  • 2015-11-15
  • 2016-07-24
  • 2015-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多