[英]Push notifications with FCM on DevExtreme/Phonegap
我使用基於PhoneGap的多平台工具DevExtreme開發了我的應用程序。
現在,我正在嘗試使用phonegap-plugin-push管理推送通知。
我的第一個簡單目標是從FCM(Firebase雲消息傳遞)發送和接收一些通知。
我更喜歡從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嗎?
然后,我正確地創建了應用程序模板並構建了apk。 但是,當然,當我將其安裝在Android設備上並嘗試從FCM發送通知時, 我在該應用上看不到任何內容。
此外,我正在嘗試在應用啟動后通過消息來管理注冊事件,但是我也沒有看到該消息 。
因此,這里沒有任何工作! 既然恕我直言,缺少文檔,您能幫我嗎?
更新:根據phonegap插件推送的文檔,我注意到我必須包括google-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 )的項目中,但我不知道它是否是對。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.