问题描述
我使用基于PhoneGap的多平台工具DevExtreme开发了我的应用.
I developed my app with DevExtreme, a multiplatform tool based on PhoneGap.
现在,我正在尝试使用phonegap-plugin-push管理推送通知.
Now, I'm trying to use the to phonegap-plugin-push manage push notifications.
我的第一个简单目标是从FCM(Firebase云消息传递)发送和接收一些通知.
My first, simple, goal is to send&receive some notifcations from FCM (Firebase Cloud Messaging).
我更喜欢从Android开始,因此,我在FCM上设置了Android应用.在这里,我获得了发件人ID.
I prefer to start with Android, so, I set my Android app on FCM. Here, I took the sender ID.
在文档之后,我对config.xml进行了如下修改:
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>
然后在index.js文件中的deviceReady事件中:
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);
});
从这里开始痛苦.
首先,我不知道pushServiceURL是否正确.如果我想从FCM发送一些通知,这是要使用的URL吗?
然后,我正确地创建了应用程序模板并构建了apk.但是,当然,当我在Android设备上安装它并尝试从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?
更新:遵循phonegap插件推送的文档之后,我注意到我必须包括google-service.json.因此,我在config.xml中写道:
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>
然后我更改了index.js中的代码:
And I changed the code in the index.js:
var push = PushNotification.init({
android: {},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
由于senderID现在位于google-services.json中.此外,我还在config.xml中删除了senderID:
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" />
我还在index.html( https://github.com/phonegap/phonegap-plugin-push/blob/master/src/js/push.js ),但我不知道这是否正确.
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.
推荐答案
Solved it. I wrote this: https://programmingistheway.wordpress.com/2017/07/19/devextremephonegap-how-to-manage-push-notifications-with-fcm/
希望有帮助.
这篇关于在DevExtreme/Phonegap上使用FCM推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!