Ionic Push not delivering notification when app is closed


#1

I am trying to set up Ionic Push on my app. I followed the starter tutorial http://docs.ionic.io/v1.0/docs/push-from-scratch and got the alert box to show up.

Then I registered for Google API GCM. I used curl to test send messages again. I turned off dev_push. The push notification is sent when the app is open or minimized.

However after I close the app, the push notification doesn’t work anymore. I thought this would be something to do with the identification / registration of the app. So I opened the app again and retested it without pressing identify/register and it still worked.

What am I doing something wrong? Does Ionic Push work when the app is close?

My second question is, for those who are experienced with ionic and push notification, I can’t seem to find much help on Ionic Push, probably since it’s in alpha. Is it easier to go with another service for example the one in Ng Cordova or Push Woosh? What are your experiences with that?

Thanks a lot in advance for your feedback / advice.

Here is my code:

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope, $rootScope, $ionicUser, $ionicPush) {

   // Handles incoming device tokens
  $rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
    alert("Successfully registered token " + data.token);
    console.log('Ionic Push: Got token ', data.token, data.platform);
    $scope.token = data.token;
  });

  // Identifies a user with the Ionic User service
  $scope.identifyUser = function() {
    console.log('Ionic User: Identifying with Ionic User service');

    var user = $ionicUser.get();
    if(!user.user_id) {
      // Set your user_id here, or generate a random one.
      user.user_id = $ionicUser.generateGUID();
    }

    // Add some metadata to your user object.
    angular.extend(user, {
      name: 'Ionitron',
      bio: 'I come from planet Ion'
    });

    // Identify your user with the Ionic User Service
    $ionicUser.identify(user).then(function(){
      $scope.identified = true;
      alert('Identified user ' + user.name + '\n ID ' + user.user_id);
    });
  };

  // Registers a device for push notifications and stores its token
  $scope.pushRegister = function() {
    console.log('Ionic Push: Registering user');

    // Register with the Ionic Push service.  All parameters are optional.
    $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) {
        // Handle new push notifications here
        // console.log(notification);
        return true;
      }
    });
  };

})

#2

Don’t use ionic push as it is in alpha. There are bound to be changes and problems. Use either push woosh or custom push notification implementation.

make sure that your push plugin is wrapped in device ready. NgCordova does not have this out of the box so $cordovaPush:tokenReceived will work if the plugins are ready and available otherwise it will not.

Just check that.


#3

If you using the cordova push-plugin you can see the special handling for getting push notifications if the app is closed - it is called coldstart.


Ionic Push - coldstart
#4

Don’t know if this is relevant to you but we were using Ionic Push to manage notifications. The thing is we weren’t able to receive notifications when app was closed and it was not an Ionic problem. The test phone is a MIUI and it has special permission to prevent apps from auto-starting. If you happen to have a custom Android so check if you have this kind of permissions activated.

Then again, this may completely irrelevant to your case.


#5

Thank you alejandroedina


#6

Same problem here. In iOS, everything works besides when I shut down the app - then no push arrives. Any solution? (I’m using Ionic push)


Ionic iOS Push Notification when app is shut-down
#7

I think Ionic Push is still in beta … so better use another plugin ( i use ngcordova push … works on IOS and Android , even when the app is closed)


#8

Are you recommending to:

  1. Change the server side - so it will not send the pushes via ionic.io, but directly via APNs
  2. In the client side user another plugin thatn Ionic.push, like ngcrodova push

Should I do both of them, or 2 is enough? What is the root cause of the problem?


#9

By the way - ngcordova push is here: https://github.com/phonegap-build/PushPlugin.git
And when I go there, it says that it is deprecated and replaced by https://github.com/phonegap/phonegap-plugin-push


#10

Okay found the problem…
Guys - you should NOT use the ionic.io gateway…
When I used the ANPs directy - everything works fine… Careful here…


#11

Yeah I know … I also need to update my code … but the concept is the same, but now they merged the different devices os (IOS and Android)


#12

I switched my server side to use directly the APNs & GCM (Instead of Ionic.io),
and in the client side, i use the cordova plugin directly, without the Ionic.push,
and finally everything works… Thank god…
I don’t know why the Ionic team let people use it when it’s not ready yet…


#13

Well … they did mention it some where it’s beta :slight_smile:


#14

Hi, I having the same issue on no notification receive when close the app.
can share your code on how to directly call APNS and GCM? Thanks


#15

Hey @jenqtat, i was able even when closing the app to send notifications ( ios only ).

Could you elaborate ?


#16

Hi @sabativi, I sending pushes via ionic.io now as per tutorial http://docs.ionic.io/docs/push-full-setup . and I able to receive the notification while my app open or minimized.

However, my app fail to receive notification while it’s off.

Are you using Ionic Push as well?


#17

Yes i follow the same tutorial. Have you been able to check the status of your notifications thanks to the api ?


#18

Hi @sabativi, Found the issue. It is my bad. As I test on MIUI phone which need to duel with the AUTOSTART feature http://en.miui.com/thread-117992-1-1.html. It working perfectly in Andoird and IOS.

Thanks for your help!! Cheer.


#19

Same here but with onesignal, any idea?