onNotification event doesn't fire when app is in background


#1

HI all,

I can’t figure it out how to make the onNotification event to run when I receive a notification and the app is in background. I’m using ionic push api v2 and everyhing works fine except for this. Does anyone know if this currently works and if that is the case what “special” options should be send through the notification api?

Example code:

    $ionicPlatform.ready(function() {
        $ionicPush.init({
            debug: true,
            onNotification: function(notification) {
                $state.go('app.login');
            },
            onRegister: function(data) {
                dtlDevice.setToken(data.token);
            }
        });
        $ionicPush.register();
    });

Thanks!!


#2

I’ve been tackling the same problem for the past 2 days.

From what I dug around, you have to use a method called deep linking to get your code to open when you access a URL that’s referenced to it. You create the URL by using a plugin called Custom URL Scheme (https://github.com/EddyVerbruggen/Custom-URL-scheme) so that whenever you visit a custom defined URL, your app will be opened up. And when that happens, you can set a flag to do the redirection.

More about this here: https://medium.com/angularjs-articles/deep-linking-in-ionic-mobile-applications-44d8b4685bb3#.s7djt1lb1

But the problem here is I have no clue how to get push notification to open that URL I defined. If you have any luck with this, please tell me how you did it!


#3

Thanks for your help coralbue,

I finally ended up not using Ionic push object, and just plain phonegap-plugin-push, sending notifications directly via GCM.
Everything works as expected.