$ionicPush undefined

Hi,

I have troubles when calling $ionicPush.register() - $ionicPush seems to be undefined.

ionic-push.js gets loaded correctly and dependencies are set:

angular.module('meetat', [
'ionic',
'ngCordova',
'ionic.service.core',
'ionic.service.push',
'meetat.controllers',
'angular-carousel',
'ngRoute',
'ui.router'])

Controller code:

.controller('LoginCntrl', function ($scope, $http, $state, $ionicLoading, $rootScope, $ionicUser, $ionicPush) {
        $scope.userId;

        var fbLoginSuccess = function (userData)
        {
            facebookConnectPlugin.getAccessToken(function (token)
            {
                $scope.initUser();
            }, function (err) {
            });
        };

        $scope.login = function () {
            facebookConnectPlugin.login(["public_profile, user_events, user_birthday, user_friends, user_photos"],
                    fbLoginSuccess,
                    function (error) {
                        alert("Login not possible.");
                    }
            );
        };

        $scope.identifyUser = function () {
            var user = $ionicUser.get();
            if (!user.user_id) {
                user.user_id = $scope.userId;
            }
            $ionicUser.identify(user).then(function () {
                $scope.identified = true;
                console.log('Identified user ' + user.name + '\n ID ' + user.user_id);
                $scope.pushRegister();
            });
        };

        // Registers a device for push notifications
        $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
                    return true;
                }
            });
        };

        $scope.initUser = function () {
            $scope.identifyUser();
            [...]
        };

        $scope.getFacebookLoginStatus = function () {
            [...]
        };
        $scope.getFacebookLoginStatus();
    })

Additional information:

  • $ionicUser.identify gets called without problems and the response is correct. Users appear @ Ionic Dashboard.
  • The error does not appear when dev_mode set to true,
  • All API keys are set (gcm_id as well) and verified multiple times.

Thanks for your help.

anybody here who can help me?

this could help

Possible errors like missing gcm_id or testing on virtual devices are not the problem in my case…

+1

I have exactly the same problem …

Hi Adel,

I got the problem solved by manually adding “ionic plugin add https://github.com/phonegap-build/PushPlugin.git”. The strange thing is that I also had the problem on the official ionic demo app - one would think that all dependencies are added automatically…

Thank you it works !

This dependency should be mentionned in the documentation because i have followed the doc step by step and this problem occured.

hi @Adel and all, i want to ask about badges “canSetBadge: true”, but in ionic icon not recieve or show budge. Is there any can help me? thanks