我计划整合针对Chrome的推送通知(推送API和通知API).
成功订阅后,Chrome服务器会向客户端发送一些特殊令牌("端点"),您可以使用该令牌识别客户端并发送任何推送消息.
来自doc:
端点应该保存在服务器上,供每个用户使用,因为您需要它们以后发送推送消息.
我有几个问题:
push push-notification google-cloud-messaging web-push push-api
我使用的是 46.0a1 版本的 Firefox Nightly(OS X 只有 42v,而 Push API 需要 43v)。
我收到此错误:
DOMException [AbortError: "Error retrieving push subscription"
code: 20
nsresult: 0x80530014]
Run Code Online (Sandbox Code Playgroud)
这是抛出此错误的片段:
navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe()
.then(function (subscription) {
endpoint = subscription.endpoint;
console.log('subscription endpoint: ', subscription.endpoint);
subscribeOnServer();
})
.catch(function (e) {
// here that error is raised
errorNotification.innerHTML = 'Unable to subscribe to push';
}
});
});
Run Code Online (Sandbox Code Playgroud)
在 Chrome 中,这个地方不会抛出任何东西,我通过正确的端点获得订阅。
我正在开发渐进式网络应用程序,我想为推送通知实施分析.
如何为推送通知添加分析,以便我能够跟踪和记录有多少人点击通知以及有多少人关闭该通知而不点击它.
push-notification service-worker web-push push-api progressive-web-apps
我设法通过类似的方法将空推送通知发送到 chrome 和 firefox,尽管我试图使我的通知更详细,但是我找不到使用 .net 作为后端的详细 webpush 通知的示例。
我的 Firefox 示例如下:
Shared Function sendPushFox(ByVal value As String) As String
Dim toret As String = ""
Dim query As String = "SELECT subscribeid FROM custom_user_data WHERE NOT subscribeid = ' ';"
Dim connection As New MySqlConnection(Utils.connectionString) : connection.Open()
Dim command As MySqlCommand = New MySqlCommand(query, connection)
Dim reader As MySqlDataReader = command.ExecuteReader()
Dim regList As New List(Of String)
Do While reader.Read
regList.Add(reader.GetString(0))
Loop
Dim query2 As String = "SELECT p256dh FROM …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个带有 JS 代码和 PHP 后端的网络推送通知示例。任何人都可以分享示例代码或教程吗?
我正在我的网站上开发网络推送通知.我遵循Google 的Web推送通知和Mozilla 的服务工作者手册.
我已经在Google Chrome v50 +上进行了测试,一切正常,但我会在调用navigator.serviceWorker.register('./push-service-worker.js')
函数时在Firefox 44,45,46,52,最新的Firefox(版本57.0.4 64位)上收到以下错误.
TypeError:位于http:// localhost:9600/push-service-worker.js的 ServiceWorker脚本,范围为http:// localhost:9600 /在安装期间遇到错误.
这是我的代码:
在controller.js中注册ServiceWorker
navigator.serviceWorker.register('push-service-worker.js')
.then((registration) => {
return registration.pushManager.getSubscription()
.then((subscription) => {
if (subscription) {
return subscription;
}
var subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: buildApplicationServerKey(),
};
return registration.pushManager.subscribe(subscribeOptions);
});
})
.then((subscription) => {
sendSubscriptionToServer(subscription);
})
.catch((err) => {
console.log('Unable to subscribe to push: ', err);
});
Run Code Online (Sandbox Code Playgroud)
推送服务worker.js
'use strict';
self.addEventListener('push', (event) => {
var payload = event.data.json();
var …
Run Code Online (Sandbox Code Playgroud) 我正在使用角度7创建一个PWA,但我正在努力推送通知.
我下面的教程为这个和这个使用SWPush,索然无味密钥对.我可以订阅和退订和我的服务器部分工作为好,但不幸的是教程不包括显示应用程序的实际通知.
据我所知,通知会自动弹出而不在代码中调用它,对吧?你只需订阅,其余的就是ngsw.不幸的是,他们并没有出现在我的案例中.我只能通过在代码中手动调用它们来显示它们,如下所示:
this.swPush.messages.subscribe(
(notification: any) => {
console.log("received push message", notification);
let options = {
body: notification.body,
icon: "assets/icon/favicon.png",
actions: <any>notification.actions,
data: notification.data,
vibrate: [100, 50, 10, 20, 20]
};
this.showNotification(notification.title, options)
},
err => {
console.error(err);
}
);
[...]
showNotification(title: string, options: NotificationOptions) {
navigator.serviceWorker.getRegistration().then(reg => {
reg.showNotification(title, options).then(res => {
console.log("showed notification", res)
}, err => {
console.error(err)
});
});
}
Run Code Online (Sandbox Code Playgroud)
但这似乎仅在app/page处于前台时才有效.否则,我会收到"网站已在后台更新"的通知.显然我在这里做错了什么.但是什么?
当应用程序在后台时,我该怎么做才能显示通知?
有没有办法处理通知上的点击事件?
ng文档在这里非常稀疏.
push-notification service-worker web-push progressive-web-apps angular
我正在升级使用针对Google Chrome和Firefox的Wen Push Notification的网站。它已经运行了两年。它拥有近2-3百万订户。但是现在,它的服务器速度很慢,这就是为什么我将Web推送通知部分迁移到AWS lambda
可伸缩解决方案的原因,因为订阅者正在增加。
由于项目是很早建立的,因此它使用GCM Keys
代替Firebase Keys
。在迁移期间,我发现非常奇怪的事情是,在主服务器上运行良好的相同GCM密钥在上无法运行aws lambda
。而且我得到了401 - Legacy Server Key
错误。Mozilla web push are working great
我阅读了GCM文档,发现GCM已过时。在2019年4月之后,它将不再起作用。另外,我看不到任何GCM控制台。我转到firebase控制台并创建了一个新项目,并尝试使用new发送推送通知fcm_key
,这一次响应了200 and MisMatchSenderId
,这很有意义,因为此订阅信息是从Google api使用提取的gcm sender id
。现在我有以下问题,如果有人知道答案,请告诉我。
我如何才能将电流迁移GCM project
到其他地方,FCM project
以gcm sender id
保持原样?我可以吗 ?
使用old订阅了近2-3百万个订阅者GCM sender id
,如果我不能迁移,那有什么解决方案。我会失去所有订阅者,还是需要为每个用户重新订阅并获取新的订阅信息?
如果我需要为每个浏览器重新订阅,它会再次要求允许和阻止权限吗?
您的帮助将不胜感激!
firebase google-cloud-messaging web-push firebase-cloud-messaging
我已经使用 TWA 和本教程成功地为我的网站创建了一个 apk。
https://developers.google.com/web/updates/2019/02/using-twa
但我不知道我应该如何为我的 apk 添加推送通知。有两种方法: 1. Web-push 2-android push。他们都有单独的SDK。
问题是,如果我使用 web-push,chrome 怎么知道它不应该去网站,而应该去 app.
而且我也有使用 android sdk 进行推送通知的问题。push 的教程说你应该在主要活动的 onCreate 事件中放置一些代码。我的项目(用 twa 教程制作)没有活动。