cordova-plugin-firebase-messaging
我可以使用firebase控制台向android手机发送推送通知,但是那些已安装的apk文件会发生什么,所有都接收推送通知,但我想发送给特定用户,所以我想获得FCM令牌。我尝试过,在“index.js”文件中,onDeviceReady 函数我调用以下函数来获取令牌。
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
FCMPlugin.getToken(function(token){
alert(token);
});
}
当我构建并安装 apk 文件并在移动设备中打开时,但打开设备时没有任何显示。
我的 Cordova 版本是 11.0.0
安装的插件是
cordova-plugin-fcm-with-dependecy-updated 7.8.0 "Cordova FCM Push Plugin"
非常感谢任何回复。问候 阿拉文
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.10.0/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN (get it from your firebase project)",
databaseURL: "YOUR_FIREBASE_DB_PATH",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_SENDERS_ID",
appId: "YOUR_APP_ID",
measurementId: "G-4TN45ZQFFJ"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
确保您已完成以下操作
}
cordova.plugins.firebase.messaging.onBackgroundMessage(函数(有效负载)
{ //对收到的有效负载/收到的通知执行一些操作
}
https://fcm.googleapis.com/fcm/send