2017-07-18 62 views
0

我使用基於PhoneGap的多平臺工具DevExtreme開發了我的應用程序。在DevExtreme/Phonegap上使用FCM推送通知

現在,我正在嘗試使用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發送通知,我沒有在應用程序中看到任何內容。

此外,我想應用程序啓動後用消息來管理註冊事件,但我沒有看到這樣的信息太

所以,這裏沒什麼工作!因爲,恕我直言,缺乏文件,你能幫助我嗎?

UPDATE: 下面的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現在在谷歌,services.json。此外,我刪除了senderID也是在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)內我的項目這個文件,但我不知道這是否是正確的。

回答