【发布时间】:2019-08-19 00:12:28
【问题描述】:
我已按照此链接进行集成 https://medium.com/@a.adendrata/push-notifications-with-angular-6-firebase-cloud-massaging-dbfb5fbc0eeb
这里是 firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js');
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({
'messagingSenderId': '426004542538'
});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();
下面是包含配置信息的环境文件
export const environment = {
production: false,
firebase: {
apiKey: "AIzaSyBvhz9Ml0Nd68SR8BRDxO10q6Hyptcnrjk",
authDomain: "pushnotification-7fd02.firebaseapp.com",
databaseURL: "https://pushnotification-7fd02.firebaseio.com",
projectId: "pushnotification-7fd02",
storageBucket: "pushnotification-7fd02.appspot.com",
messagingSenderId: "426004542538"
}
};
在邮递员中,我使用 curl 命令进行 firebase
curl -X POST \
https://fcm.googleapis.com/fcm/send \
-H 'Authorization: key=AAAAYy_ZdEo:AP..........' \
-H 'Content-Type: application/json' \
-d '{
"notification": {
"title": "Hello World",
"body": "This is Message from Admin"
},
"to" : "fDFFOme2rEI:APA91bHnZGmt6ae5Jyuv2vI4WGBOg3XKMwtHpZIFAYa9slacU9Uvam_7OHSUs0k_TFwRqDZFwZ6WF2IqdOH7Mj1u6BSbunsPuYxeH1zFivnPYfQoZfxqbSkxQYDMDoO21xjUpSDWxqbp"
}'
邮递员的反应是
{
"multicast_id": 4927361125379832815,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1553764018334820%2fd9afcdf9fd7ecd"
}
]
}
虽然邮递员的响应是 200 成功,但数据仍然没有存储在 firebase 中并且我没有收到任何推送通知。我正在运行 ng serve --port 3000,它部署在 localhost:3000 上。
【问题讨论】:
标签: firebase push-notification angular6 angular-service-worker