我已经使用Workbox库实现了服务人员。对于Web推送通知,我们通过WebPush(https://github.com/web-push-libs/web-push-csharp)
使用FCM现在,我要发送一个动态推送通知图标。图标以base64格式保存在数据库中。当我尝试使用WebPush从服务器端发送推送时,抛出异常:“错误请求”。
因此可以使用Base64代替图像URL吗?
在Google的developer page中,它提到“某些浏览器可能要求通过HTTPS投放图片”。那是问题吗?
我已经尝试通过webPush将base64发送到FCM。它没有用。
如果我使用base64对图标进行硬编码,它将起作用。
notificationData.icon = 'data:image/png;base64,iVBORw0KGg....'; //its working.
// PUSH NOTIFICATIONS Event
self.addEventListener('push', function(event) {
console.log('[Service Worker]: Received push event', event)
var notificationData = {}
if (event.data.json()) {
notificationData = event.data.json().notification // "notification node is specific for @angular/service-worker
} else {
notificationData = {
title: 'Notification',
message: 'You got notification',
icon: './assets/imgs/notificationicon.jpg'
}
}
notificationData.icon = notificationData.icon;
self.registration.showNotification(notificationData.title, notificationData)
})
//Server Side WebPush
try {
pushMessage.notification.icon = SystemInfo.Settings.NotificationIcon; // Base64 String
_client.SendNotification(subscription.ToWebPushSubscription(), JsonConvert.SerializeObject(pushMessage), _vapidDetails);
} catch (WebPushException e) {
_logger.Error(e.Message); // Bad Request
}
我已经使用Workbox库实现了服务人员。对于Web推送通知,我们正在通过WebPush(https://github.com/web-push-libs/web-push-csharp)使用FCM。现在,我要发送的是...
我们不能将base64与推送通知一起使用,因为推送消息大小不能超过4 KB的FCM文档统计信息。