1

I am trying to implement push notifications in Ionic V1 using $cordovaPushV5 but I am not able to get to work. I am able to get the device registration ID but when I test notifications using Firebase Cloud Messaging, it doesnt work. Below is app.js code -

   // ionic Starter App
    // angular.module is a global place for creating, registering and retrieving Angular modules
    // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
    // the 2nd parameter is an array of 'requires'
    // 'starter.controllers' is found in controllers.js
    var app = angular.module('starter', ['ionic', 'ngCordova'])
        .run(function ($ionicPlatform, $cordovaPushV5, $rootScope, $cordovaLocalNotification) {
        $ionicPlatform.ready(function () {
            // hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            if (cordova.platformId === 'ios' && window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                cordova.plugins.Keyboard.disableScroll(true);
            }
            if (window.StatusBar) {
                // org.apache.cordova.statusbar required
                window.StatusBar.styleLightContent();
            }
            console.log('app.js');
            var options = {
                android: {
                    senderID: "981686413111"
                },
                ios: {
                    alert: "true",
                    badge: "true",
                    sound: "true"
                },
                windows: {}
            };
            $cordovaPushV5.initialize(options).then(function (result) {
                // start listening for new notifications
                $cordovaPushV5.onNotification();
                // start listening for errors
                $cordovaPushV5.onError();
                // register to get registrationId
                $cordovaPushV5.register().then(function (registrationId) {
                    // save `registrationId` somewhere;
                    console.log(registrationId);
                    localStorage.setItem('deviceID', registrationId);
                }, function (err) {
                    console.log(err);
                });
            });
            $rootScope.$on('$cordovaPushV5:notificationReceived', function (event, data) {
                console.log(data);
            });
            $rootScope.$on('$cordovaPushV5:errorOccurred', function (event, error) {
                console.log("notification error occured");
                console.log("event object: ", event);
                console.log("error object: ", error);
            });
            $cordovaPushV5.finish().then(function (result) {
                // OK finished - works only with the dev-next version of pushV5.js in ngCordova as of February 8, 2016
            }, function (err) {
                // handle error
                console.log('finish error');
            });
            //$cordovaPushV5.unregister();
        });
    });

    //# sourceMappingURL=app.js.map

Here is my screenshot of FCM history -

FCM History

I follow the following links to implement - https://github.com/yafraorg/yafra/wiki/Blog-Ionic-PushV5

What am I missing ?

  • Have you find something? Me too $cordovaPushV5.onNotification() is not fired when receiving a notification. – Mathieu G Feb 16 '17 at 16:20
  • This is what I did, I kept the code for PushV5 in my script and added the code for OneSignal as well. I tried OneSignal push test and I received 2 notifications. One was from OneSignal event and other from PushV5. I guess FCM push test doesnt work. I wasnt sure what was going on, so I gave up on pushV5 and used OneSignal. – abhilash hegde Feb 18 '17 at 20:36

0 Answers0