IonicPush: I can't push notification when outside the app


#1

Dear all

I’m implement feature PushNotification in the my application follow this document http://docs.ionic.io/docs/push-overview .

Then got token and user identify, but i can’t push notification outside the app, or show an alert on my screen, or play a sound. Just only see alert notificaion when open application again.

My application has feature chat, so wanna push notification when user outside app or close application. Can you help me to finish for this issue :smile:

Using code below:

var userApplication = $ionicUser.get();
if(!userApplication.user_id) {
      // Set your user_id here, or generate a random one.
      userApplication.user_id = $ionicUser.generateGUID();
};
angular.extend(userApplication, {
      name: 'Phan Thinh',
      bio: 'I come from planet Ion'
});
$ionicUser.identify(userApplication).then(function(){

	$ionicPlatform.ready(function() {
           register();
    });

},function(err){

});

function register(){

$ionicPush.register({
canShowAlert: true, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function(notification,event) {
// Handle new push notifications here
}
},userApplication);

$rootScope.$on(’$cordovaPush:tokenReceived’, function(event, data) {
// console.log(‘Got token’, data.token, data.platform);
console.log(“Got token”);
console.log(data);
// Do something with the token
});

}


Ionic Push not registering device tokens
#2

It’s resolved

Just remove pushwoosh “cordova plugin rm com.pushwoosh.plugins.pushwoosh” then follow nice example https://github.com/hollyschinsky/PushNotificationSample

If application not alert “Would do you like notification…” so add code to xcode below:

   if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        
        [application registerForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }

#3

Hi, phanthinh,

I basically just follow the official docs to use push as:

$ionicPush.register().then(function(t) {
return $ionicPush.saveToken(t);
}).then(function(t) {
console.log(‘Token saved:’, t.token);
});

and I test it in browser, but it doesn’t give me the device token.

then i found your solution as below:

$ionicPush.register({
canShowAlert: true, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function (notification, event) {
// Handle new push notifications here
}
});

                $rootScope.$on('$cordovaPush:tokenReceived', function (event, data) {
                    // console.log('Got token', data.token, data.platform);
                    console.log("Got token");
                    console.log(data);
                    // Do something with the token
                });

It doesn’t work too, do you have a better idea how to work with the $ionicPush.register().

Thanks .