Hi,
I created an app with push notifications.
On my device it works like a charm. Im using Samsung galaxy 4.
My friend installed my app on his LG g3 and his user id appears in the users section in the ionic dashboard but the device registration token is not saved and remains empty so he cant recieve notifications…
What could be the problem and how can it be fixed?
.service('PushNotificationService', function( $ionicUser, $ionicPush, $rootScope, $http, $localStorage) {
console.log("SERVICE: PushNotificationService");
// Handles incoming device tokens
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
console.log("Successfully registered token " + data.token);
// Save the registerID in the database
$http.post( "some url", {regId: data.token}).
then(function(response) {
console.log("Successfully registered token with the WEB SERVICE");
// this callback will be called asynchronously
// when the response is available
}, function(response) {
console.log("ERROR: FAILED registering token with the WEB SERVICE");
// called asynchronously if an error occurs
// or server returns response with an error status.
});
});
var PushNotificationService = this;
PushNotificationService.identifyUser = function(){
var user = $ionicUser.get();
if(!user.user_id) {
// Set your user_id here, or generate a random one.
user.user_id = $ionicUser.generateGUID();
console.log("Generated user ID");
};
// Add some metadata to your user object.
angular.extend(user, {
name: 'Application user',
bio: 'Android app'
});
// Identify your user with the Ionic User Service
$ionicUser.identify(user).then(function(){
console.log('Identified user ' + user.name + '\n ID ' + user.user_id);
console.log("Calling the registration function");
PushNotificationService.pushRegister();
return true;
});
},
PushNotificationService.pushRegister = function(){
console.log("Start of registration function");
// Register with the Ionic Push service. All parameters are optional.
$ionicPush.register({
canShowAlert: true, //Can pushes show an alert on your screen?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function(notification) {
console.log("Recieved notification");
// Handle new push notifications here:
switch( notification.event )
{
case 'message':
$rootScope.$broadcast('notification:updated', notification);
break;
}
return true;
}
});
}
I have the exact same issue here, also on iOS devices. Push notifications work amazingly well on my device but on no other devices (Android or iOS) due to the fact the device tokens are not being registered. Would love to hear solutions if anyone has any :).