在DevExtreme / Phonegap上用FCM推送通知

我使用基于PhoneGap的多平台工具DevExtreme开发了我的应用程序。

现在,我正在尝试使用phonegap-plugin-pushpipe理推送通知。

我的第一个简单目标是发送和接收来自FCM(Firebase Cloud Messaging)的一些通知。

我更喜欢从Android开始,所以我在FCM上设置了我的Android应用程序。 在这里,我拿了发件人ID。

在文档之后,我修改了config.xml如下:

<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> 

然后,在index.js文件的deviceReady事件中:

  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); }); 

在这里开始痛苦。

首先,我不知道pushServiceURL是否正确。 如果我想从FCM发送一些通知,这是这个URL吗?

然后,我正确地创build了应用程序模板并构build了apk。 但是,当然,当我将其安装在我的Android设备上,并尝试从FCM发送通知时, 我在应用中看不到任何内容。

此外,我试图在应用程序启动后用消息来pipe理注册事件,但是我也没有看到该消息

所以,这里没有任何工作! 因为,恕我直言,缺乏文件,你能帮助我吗?

更新:继phonegap插件推文档后,我注意到我必须包括谷歌service.json。 所以,我写在我的config.xml中:

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

我改变了index.js中的代码:

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

由于senderID现在位于google-services.json中。 另外,我还在config.xml中删除了senderID:

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

我也在我的项目index.html( https://github.com/phonegap/phonegap-plugin-push/blob/master/src/js/push.js )中包含这个文件,但我不知道它是对。

解决了它。 我写这个: https : //programmingistheway.wordpress.com/2017/07/19/devextremephonegap-how-to-manage-push-notifications-with-fcm/

希望能帮助到你。