F
F
FoxUmkov2013-11-21 22:46:39
Google
FoxUmkov, 2013-11-21 22:46:39

How to implement push notifications based on Google App Engine server and Unity3d client?

There is a GAE server that responds to simple POST and GET requests, and there is a game written in the Unity3d engine. How to make push notifications work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stepan, 2013-11-22
@FoxUmkov

function send_notification($registatoin_ids, $message) {
        // include config
        include_once '/home/smski/www/api/gcm/config.php';
 
        // Set POST variables
        $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
        $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);
        echo $result;

S
Stepan, 2013-11-21
@L3n1n

Have you ever figured out how notifications work in android?
1. In the application, we get the Google RegId (or whatever it is).
2. We send the RegId to the server and save it to the database.
3. When you need to send a Push to the user, look for his RegId and send it to Google Api.
4. The user receives our push notification.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question