簡體   English   中英

Phonegap-plugin-push處於打開狀態。(“ notification”)不會觸發

[英]Phonegap-plugin-push's on.('notification') doesn't fire

我正在嘗試使用phonegap-plugin-push在我的混合應用程序中實現推送通知,該應用程序是由reactjs和cordova構建的。

我已經正確設置了一切(添加了插件,已在firebase中注冊,google-services.js文件在正確的位置)。

我把它放在我的index.js文件中:

 import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; // ReactDOM.render(<App />, document.getElementById('root')); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: const startApp = () => { ReactDOM.render( <App />, document.getElementById('root') ); serviceWorker.unregister(); var push = window.PushNotification.init({ android:{} }); console.log(push); push.on('registration', function (data) { console.log("on registration"); console.log(data); }); push.on('notification', function (data) { // console.log("notification received"); alert("Title:"+data.title+" Message:"+ data.message); }); push.on('error', function (e) { console.log(e.message) }); } if(!window.cordova) { console.log("cordova is null"); startApp(); } else { document.addEventListener('deviceready', startApp, false); } 

當我在android模擬器上運行該應用程序,並使用chrome inspect設備對其進行調試時,我可以看到on('registration')被觸發並正常工作。 但是,當我嘗試將通知從Firebase發送到設備時,什么也沒發生。 這是我撰寫通知的方式:

 *Notification title(optional): title Notification text: test noti Notification label: test noti *Target App com.allen.thomas.netdi //the package name that i registered *Scheduling i chose "send now" *Conversion events(optional) didn't do anything with this *Additional options(optional) //left the Android "Notification Channel" field blank //For custom data I filled in the following keys-values title Test Notification body Please work! badge 1 content-available 1 priority: high sound: enabled expires: 4 weeks 

然后我點擊發布。 但是什么也沒發生。 我不明白這是什么問題?

您的套件名稱與Firebase中的項目相符嗎?

您是否已在Android Studio中啟用Android支持存儲庫47+版本? 參見: https : //github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md#android-details

看來我想出了解決辦法。 我需要做的就是在on('notification)的回調函數中添加以下代碼行:

 push.finish(function(){ console.log("notification received successfully"); }) 

它解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM