2014-12-04 75 views
0

我必須針對大量設備(每天超過10k個設備)發送帶有不同消息的推送通知。但有時它不接收所有設備。我設置了一個功能pushNotificationToUsers($heading,$message,$registraionids)發送推送通知和我不確定我的方法是否正確,如果我錯了,請糾正我。發送到GCM的大規模推送通知

function pushNotificationToUsers($heading,$message,$registraionids){ 
     //array of registration ids in $registraionids   
     $key="xxxxxxxxxxx"; 
     // Set POST variables 
     $url = 'https://android.googleapis.com/gcm/send'; 
     $fields = array(
         'registration_ids' =>,$registraionids, 
         'data'    => array("message" => $message,"title"=>$heading,"soundname"=>"beep.wav"), 
         ); 
     $headers = array(
          'Authorization: key=' . $key, 
          'Content-Type: application/json' 
         ); 
     // Open connection 
     $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); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
     // Execute post 
     $result = curl_exec($ch); 
     // Close connection 
     curl_close($ch); 

     } 

我使用PHP在我的服務器端

回答

1

對於Android,

在GCM的郵件大小限制爲4個字節。

https://developer.android.com/google/gcm/server.html#params

在C2DM消息大小限制爲1024個字節。 (已棄用)

https://developers.google.com/android/c2dm/#limitations

對於iOS,

在IOS的大小限制爲256個字節,但由於引入的iOS 8的已更改爲2KB!

https://forums.aws.amazon.com/ann.jspa?annID=2626

此外,請參閱下面充塞

谷歌取代GCM C2DM後,他們脫掉所有限制。

http://developer.android.com/google/gcm/c2dm.html#history

你碰上GCM文件的唯一限制是:

http://developer.android.com/google/gcm/adv.html#lifetime

我想這個答案是很清楚你的問題。

+0

我的方法正確嗎? – 2014-12-04 04:38:46

+0

感謝讓我檢查 – 2014-12-04 04:41:59

+0

接受&投票答案,如果它可以幫助你 – VVB 2014-12-04 04:42:45