You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
Device seems to register successfully and I receive a token, and there is no error when sending a push message to GCM, but nothing happens at the phone. My iOS device can receive notifications using the same code.
Reproduce Scenario (including but not limited to)
Download the ionic starter project and install ngCordova.
Register a new GCM project with your bundle ID.
Install this plugin using the sender ID from the GCM project.
Use this code snippet to register your device
var _registered = false, _inprogress = false, _push, _gcm_id, _device;
this.init = function(){
_inprogress = true;
$ionicPlatform.ready(function(){
// If already registered or not signed in
if(_registered || ['Android','iOS'].indexOf($cordovaDevice.getPlatform()) == -1) return; // Ensure that we're running on Android or iOS
// Push Notifications Init
var push = PushNotification.init({
android: {
senderID: "1234567890" // GCM Sender ID (project ID)
},
ios: {
alert: "true",
badge: "true",
sound: "false",
senderID: "1234567890" // GCM Sender ID (project ID)
}
});
_push = push;
push.on('registration', function(data){
_gcm_id = data.registrationId;
// Post our GCM and device information to our API
$http.post('http://MYAPIURL.com/registerpn', {
gcm_id: data.registrationId,
device: $cordovaDevice.getDevice()
}).then(
function(res){
console.log("Registered on API...");
_registered = true;
_inprogress = false;
},
function(err){
console.log("error registering for PN", err);
_inprogress = false;
}
);
});
push.on('notification', function(data){
// Here is what we will do if we get a push notification while using the app
console.log("GOT PN", data);
});
push.on('error', function(err){
console.log("PNR Error", err);
});
});
};
this.unregister = function(){
return $q(function(resolve, reject){
_push.unregister();
return $http.post('http://MYAPIURL.COM/unregisterpn', {device: _device, gcm_id: _gcm_id})
.then(
function(success){
_registered = false;
resolve();
},
function(err){
// We didn't manage to inform the server that we unregistered
console.log("Error unregistering");
resolve();
}
);
});
};
})
use "ionic run android" to run on your device.
Use the token you receive from the registration to send a push notification to your device.
I've been trying forever to get this to work, but there must be something I'm missing. The Android unit I'm using doesn't have a sim-card, if that matters.
The text was updated successfully, but these errors were encountered:
Expected Behaviour
Android should receive a push notification.
Actual Behaviour
Device seems to register successfully and I receive a token, and there is no error when sending a push message to GCM, but nothing happens at the phone. My iOS device can receive notifications using the same code.
Reproduce Scenario (including but not limited to)
I've been trying forever to get this to work, but there must be something I'm missing. The Android unit I'm using doesn't have a sim-card, if that matters.
The text was updated successfully, but these errors were encountered: