phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

PushNotification is undefined #1903

Closed ghost closed 7 years ago

ghost commented 7 years ago

I have updated my project to phonegap 7.0.1 and using the push plugin version 2.

In my index.js file, after the device is ready, I run this code:

if (typeof PushNotification !== 'undefined') {
          var push = PushNotification.init({
              android: {

              },
              ios: {
                  alert: "true",
                  badge: "true",
                  sound: "true"
              },
              windows: {}
          });

          push.on('registration', function (data) {
              // data.registrationId
              alert(data.registrationId);
              DevExpress.ui.notify("Device registered " + data.registrationId, "success", 3000);
          });

          push.on('notification', function (data) {
              // data.message,
              // data.title,
              // data.count,
              // data.sound,
              // data.image,
              // data.additionalData
              DevExpress.ui.notify(data.message, "info", 10000);
          });

          push.on('error', function (e) {
              // e.message
              DevExpress.ui.notify(e.message, "error", 10000);
          });
      }
      else
          alert("else!!!");

This used to work like charms, now it doesn't. Why?

This is also my confing.xml file

<widget id="com.devexpress.apptemplate" version="1.0" versionCode="1">
  <name>ApplicationTemplate</name>
  <description>Template</description>
  <preference name="phonegap-version" value="cli-7.0.1" /> 
  <preference name="permissions" value="none" />
  <preference name="prerendered-icon" value="true" />
  <preference name="android-windowSoftInputMode" value="adjustPan" />
  <preference name="SplashScreen" value="splash" />
  <preference name="SplashScreenDelay" value="60000" />
  <preference name="AutoHideSplashScreen" value="false" />
  <preference name="SplashShowOnlyFirstTime" value="false" />
  <preference name="FadeSplashScreen" value="false" />
  <preference name="ShowSplashScreenSpinner" value="false" />
  <preference name="DisallowOverscroll" value="true" />
  <preference name="StatusBarOverlaysWebView" value="false" />
  <preference name="StatusBarBackgroundColor" value="#000000" />
  <preference name="android-minSdkVersion" value="15" />
  <preference name="android-targetSdkVersion" value="22" />
  <plugin name="cordova-plugin-geolocation" />
  <plugin name="cordova-plugin-splashscreen" onload="true" />
  <plugin name="cordova-plugin-whitelist" />
  <plugin name="cordova-plugin-ios-longpress-fix" />
  <plugin name="cordova-plugin-statusbar" onload="true" />
    <plugin spec="https://github.com/phonegap/phonegap-plugin-push.git" source="git" />
    <platform name="android">
    <resource-file src="google-services.json" target="google-services.json" />
  </platform>
  <platform name="ios">
    <resource-file src="GoogleService-Info.plist" />
  </platform>
  <access origin="*" />
</widget>

The first if in my code goes in the else branch. This because PushNotification is undefined. Why is it undefined? Am I missing something?

macdonst commented 7 years ago

@pieruz what version of cordova-android or cordova-ios do you use? Run cordova platforms or phonegap platforms to find out.

ghost commented 7 years ago

@macdonst Sorry for the dumb question, but how can I do this check using DevExtreme?

macdonst commented 7 years ago

@pieruz No clue. I've never used DevExtreme. Probably should ask them.

ghost commented 7 years ago

@macdonst I asked, I will come back here with the answer

ghost commented 7 years ago

@macdonst Ok, here I am.

Cordova-android version is 6.2.3

Cordova-ios version is 4.4.0

macdonst commented 7 years ago

@pieruz those are the supported versions for 2.0.0. Not sure why you are getting undefined. Are you building locally?

ghost commented 7 years ago

@macdonst I created the template in the phonegap online utility and then I created the package with the DevExtreme tool. Opening the generated package, I see the version I wrote above, with the push plugin included in the plugin list

macdonst commented 7 years ago

@pieruz I'm really sorry but I don't have time to research the DevExtreme tool. You would probably be better off asking them for support. Everything you are doing looks correct.

ghost commented 7 years ago

@macdonst You're right, finally I solved with them the issue. Now it works like charms!

macdonst commented 7 years ago

@pieruz can you post what the solution was so that other can benefit if they actually search the old issues?

ghost commented 7 years ago

I wrote a summary here: https://programmingistheway.wordpress.com/2017/07/19/devextremephonegap-how-to-manage-push-notifications-with-fcm/

lock[bot] commented 6 years ago

This thread has been automatically locked.