Push notifications with FCM on DevExtreme/Phonegap

走远了吗. 提交于 2019-12-31 03:57:31

问题


I developed my app with DevExtreme, a multiplatform tool based on PhoneGap.

Now, I'm trying to use the to phonegap-plugin-push manage push notifications.

My first, simple, goal is to send&receive some notifcations from FCM (Firebase Cloud Messaging).

I prefer to start with Android, so, I set my Android app on FCM. Here, I took the sender ID.

Following the docs, I modified the config.xml as below:

<widget id="com.devexpress.apptemplate" version="1.0" versionCode="1">
  <name>ApplicationTemplate</name>
  <description>Template</description>
  <preference name="phonegap-version" value="cli-6.4.0" />
  <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-file" />-->
  <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" >
    <param name="SENDER_ID" value="123456" />
  </plugin>
  <access origin="*" />
</widget>

Then, in the index.js file, in the deviceReady event:

  var push = PushNotification.init({
      android: {
          senderID: "123456"
      },
      browser: {
          pushServiceURL: 'https://fcm.googleapis.com/fcm/send' 
      },
      ios: {
          alert: "true",
          badge: "true",
          sound: "true"
      },
      windows: {}
  });

  push.on('registration', function (data) {
      // data.registrationId
      DevExpress.ui.notify("Device registered", "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);
  });

And here starts the pain.

First of all, I don't know if the pushServiceURL is correct. Is this the URL to use if I'd like to send some notifications from FCM?

Then, I correctly created the application template and built the apk. But, of course, when I install it on my Android device and I try to send a notifications from FCM, I don't see anything on the app.

Further, I'm trying to manage the registration event with a message after the app is started, but I don't see that message too.

So, nothing work here! Since, IMHO, there is a lack of documentation, can you help me?

UPDATE: Following the documentation of phonegap plugin push, I noticed I have to include the google-service.json. So, I wrote in my config.xml:

  <platform name="android">
    <resource-file src="google-services.json" target="google-services.json" />
  </platform>

And I changed the code in the index.js:

  var push = PushNotification.init({
      android: {},
      ios: {
          alert: "true",
          badge: "true",
          sound: "true"
      },
      windows: {}
  });

Since the senderID is now in the google-services.json. Further, I removed the senderID also in the config.xml:

<plugin spec="https://github.com/phonegap/phonegap-plugin-push.git" source="git" />

I also included this file in my project within index.html (https://github.com/phonegap/phonegap-plugin-push/blob/master/src/js/push.js) but I don't know if it is right.


回答1:


Solved it. I wrote this: https://programmingistheway.wordpress.com/2017/07/19/devextremephonegap-how-to-manage-push-notifications-with-fcm/

Hope it helps.



来源:https://stackoverflow.com/questions/45169181/push-notifications-with-fcm-on-devextreme-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!