我实现了Web推送通知。获取错误的步骤:
我知道当服务人员收到推送但不显示通知时,可能会发生这种情况。但是我看到正常的通知,为什么我也看到其他奇怪的通知?我可以摆脱这种行为吗?
所以我终于为我的网站实现了成功的推送通知,但是当我按下通知并假设接收器的电脑关闭或处于睡眠模式时,gcm返回成功但通知丢失,它永远不会弹出该用户...而另一方面,我注意到facebook似乎正在做一些有助于它解决这个问题的事情..你看到一个facebook镀铬通知,一旦你重新开始重新启动铬的第一件事...是否有任何机构有任何想法至于fb如何通过这个问题?
我正在使用服务工作者进行推送通知.我正在使用XHR(Ajax)方法来获取我的通知,这是service-worker.js的代码片段:
var API_ENDPOINT = new Request('/getNotification', {
redirect: 'follow'});
event.waitUntil(
fetch(API_ENDPOINT, {credentials: 'include' })
.then(function(response) {
console.log(response);
if (response.status && response.status != 200) {
// Throw an error so the promise is rejected and catch() is executed
throw new Error('Invalid status code from API: ' +
response.status);
}
// Examine the text in the response
return response.json();
})
.then(function(data) {
console.log('API data: ', data);
var title = 'TEST';
var message = data['notifications'][0].text;
var icon = data['notifications'][0].img;
// Add this to …Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以使用网络推送通知更新网页而不显示用户与之交互的通知.基本上我想在服务器上的事件后刷新数据.
如果可以,是否仍然需要获得用户发送这些推送更新的许可?
我想知道 Web Push 背后是什么技术,例如 https://goroost.com
这是如何运作的?如何为 Web Push 配置我的服务器?我应该看什么?
我有一个服务工作者从服务器获取多个通知.问题是Chrome中的所有通知都会自动关闭,但最后一个通知除外.我究竟做错了什么?
self.addEventListener('push', function(event) {
var subscriptionId;
var sessionId;
var notification = {};
event.waitUntil(
self.registration.pushManager.getSubscription().then(function(subscription) {
subscriptionId = subscription.endpoint.split('/');
subscriptionId = subscriptionId[subscriptionId.length - 1];
notification.title = 'Yay a message.';
notification.icon = '/app/img/icon-256x256.png';
notification.tag = 'notification-tag-' + (new Date)*1;
notification.messages = [];
//get context
fetch(requestUrl,
{
method: 'post',
body: body
}).then(function(response) {
response.json().then(function(data) {
sessionId = response.headers.get('SessionId');
fetch(requestUrl + '?SessionId=' + sessionId, {
method: 'post',
headers: JSON.stringify({
'Content-Type': 'application/json'
}),
body: JSON.stringify({
data: {
subscriberId: subscriptionId
}
})
}).then(function(responce) {
responce.json().then(function(data) { …Run Code Online (Sandbox Code Playgroud) 我正在通过代码实验室进行Web推送通知,其中提到应用服务器密钥(公钥和私钥对)是必需的.
为什么我们需要应用服务器密钥来进行推送通知?我们怎样才能产生它们?是否必须拥有应用程序密钥才能使用推送通知?
如何使用googles GCM服务在浏览器中实现推送通知.实现相同的步骤是什么.
firefox google-chrome google-cloud-messaging web-push push-api