w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Android phonegap send push notification using Google Cloud Messaging using php

Here is the GCM code and its working properly with my device though its in CI framework but hope you can use it. It is compulsory to add device_id for the push and also the passphrase you'll get for the site. just try it.

function sendNotification($device_id,$message) {
        /*echo $device_id;
        echo "<br>";
        echo $message;*/

        // note: you have to specify API key in config before
        $this->load->library('gcm');
        // simple adding message. You can also add message in the data,
        // but if you specified it with setMesage() already
        // then setMessage's messages will have bigger priority
        $msg = $this->gcm->setMessage($message);
        //var_dump($message);

        // add recepient or few
        $this->gcm->addRecepient($device_id);
        //var_dump($device_id);
        // set additional data
        //$this->gcm->setData($params);
        // also you can add time to live
        $this->gcm->setTtl(500);
        // and unset in further
        //$this->gcm->setTtl(false);

        // set group for messages if needed
        //$this->gcm->setGroup('Test');
        // or set to default
        //$this->gcm->setGroup(false);
        // send
        return $this->gcm->send();
    }

Hope it'll solve your problem.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.