我使用的火力地堡云讯息。 我使用的是下面的示例链接。 https://github.com/firebase/quickstart-js
通知被接收。 我想在INDEXDB存储在服务人员的通知。
var setupDone = false;
var storage = {
setup: function() {
return new Promise(function(resolve, reject) {
var request = indexedDB.open(notificationdb, 1);
request.onsuccess = function (e) {
setupDone = true;
var db = e.target.result;
storage.db = db;
resolve();
};
request.onupgradeneeded = function (e) {
storage.db = e.target.result;
if (storage.db.objectStoreNames.contains('notifications')) {
storage.db.deleteObjectStore('notifications');
}
storage.db.createObjectStore('notifications', {
keyPath: '_id'
});
};
});
},
transaction: function (mode) {
var trans = storage.db.transaction('notifications', mode);
return trans.objectStore('notifications');
},
add: function (notification) {
return new Promise(function(resolve, reject) {
var request =
storage.transaction('readwrite').put(notification);
request.onsuccess = function () {
resolve(notification);
};
request.onerror = function() {
reject();
};
});
}
};
messaging.setBackgroundMessageHandler(function(payload) {
var notification = payload.notification;
var data = {};
data.title = notification.title;
data.message = notification.body;
data._id = getUniqueId();
data.time = Date.now();
if (!setupDone) {
storage.setup().then(function() {
storage.add(data);
});
} else {
storage.add(data);
}
return
self.registration.showNotification(notification.title,notification.body);
});
但它不是存储在INDEXDB。 创建数据库。 但不对数据进行存储。 如果有什么是错在这里请帮助。