caffeinalab / ti.goosh

GCM/FCM module for Titanium.
MIT License
52 stars 34 forks source link

Subscribe to topics #82

Closed m1ga closed 6 years ago

m1ga commented 6 years ago

Adding the possibility to subscribe to topics:

Subscribe:

TiGoosh.subscribe({
    topic: "/topics/myTopic",
    success: function(e) {
        console.log("unsub done " + e);
    },
    error: function(e){
        console.error("error")
    }
})

Unsubscribe:

TiGoosh.unsubscribe({
    topic: "/topics/myTopic",
    success: function(e) {
        console.log("unsub done " + e);
    },
    error: function(e){
        console.error("error")
    }
})

PHP test:

<?php
// API access key from Google API's Console
define('API_ACCESS_KEY', '.......');
// prep the bundle
$msg = array
(
'body' => 'This is a message sent from my http server',
'title' => 'From server side',
'priority' => 'high',
'sound' => 'default',
'time_to_live' => 3600
);
$fields = array('to' => '/topics/myTopic', 'notification' => $msg);

$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
m1ga commented 6 years ago

@Jei just saw your branch so I've forked from it to create my PR

Jei commented 6 years ago

Thank you! Did you try to compile the module though? I'm having problems with missing classes. I'll try again today and see if i can find the problem.

m1ga commented 6 years ago

With your aar files it worked without a problem. Tested it with 6.2.2.GA

Jei commented 6 years ago

Ok, i forgot to select the correct SDK 🙃. I'm using 6.2.0.GA now. I'm merging this and making a new major release, since this will not be compatible with older Titanium versions.

m1ga commented 6 years ago

ok, I didn't test it with an older version, but good that you found that issue 👍

DouglasHennrich commented 6 years ago

I have looked into platform/res/values/version.xml and it's using this8487000 version of google play service? <integer name="google_play_services_version">8487000</integer>

Shouldn't it be 11020000 or higher ?