i have a sign up controller where i identify the user and register them for push notification. like so:
function identifyUser(res) {
console.log('Ionic User: Identifying with Ionic User service');
var user = $ionicUser.get();
if (ionic.Platform.isAndroid()) {
$scope.platform = "Android"
}
user.user_id = res.data.user._id;
// Add some metadata to your user object.
angular.extend(user, {
name: res.data.user.displayName,
bio: 'I come from planet Ion',
platform: $scope.platform
});
// Identify your user with the Ionic User Service
$ionicUser.identify(user).then(function() {
$scope.identified = true;
});
}; // identify User
function pushRegister() {
console.log('Ionic Push: Registering user');
// Register with the Ionic Push service. All parameters are optional.
$ionicPush.register({
canShowAlert: false, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: false, //Can run actions outside the app,
onNotification: function(notification) {
// Handle new push notifications here
console.log(notification);
return true;
}
});
}; // push Register
$scope.authenticate = function(provider) {
$auth.authenticate(provider)
.then(function(res) {
console.log('You are now Registered', res);
identifyUser(res);
var confirmPopup = $ionicPopup.confirm({
title: 'Allow push notification',
template: 'Allow push notification'
});
confirmPopup.then(function(res) {
if (res) {
if ($scope.identified) {
pushRegister();
console.log('You are sure');
}
} else {
console.log('You are not sure');
}
});
$state.go('app.categories');
}, handleError);
}
However this work as long as i don’t terminate the app, if i did terminated the app and re-open it. still getting the push notifications but can’t handle them in my case i log them in the console for now.
onNotification: function(notification) {
// Handle new push notifications here
console.log(notification);
return true;
}