IO gcm无法在后台工作,只能在前台php脚本

时间:2015-08-24 12:41:09

标签: php android ios google-cloud-messaging

我的代码在这里 请仔细看 IOs gcm无法在后台工作,仅在前台PHP脚本中工作

     $data   = array('message' =>$msg,
    'contentTitle'      => $msg,
     "tickerText" => "some ticker text", 
     "contentTitle" => "some content title",
     "contentText" => "some content description text",
     "sound"=> "default",
     "vibrate" => "false",
     "otherCustomData" => "some value" 

                        );
        $fields = array(
            'registration_ids' => $registrationIDs,
            'data' =>  array("message" => $data),
            'content_available' => true
        );
            //have to change
            $headers = array(
            'Authorization: key=IDSSSSSSS',
            'Content-Type: application/json'
        );
        }


        $ch = curl_init();

        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);
        // print_r($result);
        if ($result === FALSE)
        {
            die('Curl failed: ' . curl_error($ch));
        }

        // Close connection
        curl_close($ch);
        echo $result;

我的Ios开发人员告诉我它只在前台工作而不是在后台工作。这在android中正常工作 请快点帮忙 提前致谢

1 个答案:

答案 0 :(得分:0)

您需要在邮件中加入notification参数。这样,GCM将通过APNS传递您的消息。或者,使用content_available

https://developers.google.com/cloud-messaging/http-server-ref#notification-payload-support