ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.06k forks source link

Uncaught ReferenceError: PushNotification is not defined(…) #1370

Open stoconnor opened 7 years ago

stoconnor commented 7 years ago

At my wits end with $cordovaPushV5! Keep getting the following error:

ng-cordova.js:6378 Uncaught ReferenceError: PushNotification is not defined(…)

Problem points to the following line: push = PushNotification.init(options);

Using the latest Cordova CLI, ng-cordova. This through testing on the device and below is my code for initializing:

$ionicPlatform.ready(function() {
localStorage.myPush = ; // I use a localStorage variable to persist the token

        $cordovaPushV5.initialize(  // important to initialize with the multidevice structure !!
            {
                android: {
                    senderID: "XXXX"
                },
                ios: {
                    alert: 'true',
                    badge: true,
                    sound: 'true',
                    clearBadge: true
                },
                windows: {}
            }
        ).then(function (result) {
            $cordovaPushV5.onNotification();
            $cordovaPushV5.onError();
            $cordovaPushV5.register().then(function (resultreg) {
                localStorage.myPush = resultreg;
                console.log(resultreg)
                var confirmPopup = $ionicPopup.alert({
          title: 'Popup',
          template: resultreg
          });
                // SEND THE TOKEN TO THE SERVER, best associated with your device id and user
            }, function (err) {
                // handle error
            });
        });

Been at this for hours at this stage, my package.json file:

"dependencies": {
    "gulp": "^3.5.6",
    "gulp-sass": "^2.0.4",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0"
  },
  "devDependencies": {
    "bower": "^1.3.3",
    "gulp-util": "^2.2.14",
    "shelljs": "^0.3.0"
  },
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard",
    "cordova-plugin-inappbrowser",
    "cordova-plugin-contacts",
    "cordova-plugin-geolocation",
    "phonegap-plugin-push"
  ],
  "cordovaPlatforms": [
    "ios",
    "android"
  ]
}

Have the following in my config.xml also:

    <plugin name="phonegap-plugin-push" spec="~1.8.3">
        <variable name="SENDER_ID" value="XXXX" />
    </plugin>

I've even tried building a release version and installing it on the device to be 100% but to no avail. Is this an issue with ngCordova as the error suggests?

gortok commented 7 years ago

You don't have the underlying push notification plugin installed.

stoconnor commented 7 years ago

Thanks for the quick response. I have "phonegap-plugin-push" installed, is there another plugin I'm missing?

gortok commented 7 years ago

Have you tried the plugin from: https://github.com/Jewelbots/parse-phonegap-plugin-push ? Also the parse-phonegap-plugin-push on that repo

gortok commented 7 years ago

Also keep in mind this doesn't work when you are running it in the web browser or emulating a device. It has to be on the physical device to work.

stoconnor commented 7 years ago

The other plugin gives me the same error. I'm running on a device and have even tried a signed release version to be sure.

I'll try downgrading cordova to see if it makes a difference

trifroggy commented 7 years ago

As I am running into the very same problem as you, I was wondering if you've had any luck resolving the issue (downgrading for example). Thank you!

aboalwi commented 7 years ago

Same here.. anything new ?

aboalwi commented 7 years ago

Just added my code inside
$ionicPlatform.ready(function() { }); everything works fine and no error xd