Я пытаюсь внедрить push-уведомления в моем гибридном приложении, построенном с реагированием и кордовой, используя phonegap-plugin-push.
У меня все настроено правильно (добавлен плагин, зарегистрированный в 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
тогда я решил опубликовать. Но ничего не случилось. Я не понимаю, в чем здесь проблема?