Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在移动设备上,有一个稳定的33%的未送达推送通知比率,我不知道为什么_Android_Web Push - Fatal编程技术网

Android 在移动设备上,有一个稳定的33%的未送达推送通知比率,我不知道为什么

Android 在移动设备上,有一个稳定的33%的未送达推送通知比率,我不知道为什么,android,web-push,Android,Web Push,我有一个网站,在那里我为用户注册了一名服务人员。我将推送通知订阅信息保存在后端,并在一天中的特定时间发送推送通知。因为我的用户大多生活在不同的时区,所以我使用一个队列,它可以在正确的时间发送推送 我通过http请求将统计信息保存在服务工作者中,如果用户单击推送通知,我也会跳转跟踪url。我还根据队列使用者服务跟踪尝试发送的推送通知数量 由于某些原因,根据服务人员的统计数据,有33%的未送达消息是稳定的。例如: 假设我每天发送大约20000个推送通知,根据服务人员的说法,“显示”事件只触发大约12

我有一个网站,在那里我为用户注册了一名服务人员。我将推送通知订阅信息保存在后端,并在一天中的特定时间发送推送通知。因为我的用户大多生活在不同的时区,所以我使用一个队列,它可以在正确的时间发送推送

我通过http请求将统计信息保存在服务工作者中,如果用户单击推送通知,我也会跳转跟踪url。我还根据队列使用者服务跟踪尝试发送的推送通知数量

由于某些原因,根据服务人员的统计数据,有33%的未送达消息是稳定的。例如: 假设我每天发送大约20000个推送通知,根据服务人员的说法,“显示”事件只触发大约12000-14000次

有人知道为什么会这样吗

  • 在chrome桌面上,数以万计的推送通知中的每一个都会到达
  • 在移动设备上,它们不是。 这意味着故障要么在于谷歌服务,要么在于服务人员与某些移动设备的兼容性
import { serviceWorkerRoutes } from 'src/route-config';

const requestParams = {
  headers: {
    'Content-Type': 'application/json',
  },
  method: 'POST'
};

self.addEventListener('install', () => {
  // the service worker must be activated as soon as it's finished installing
  self.skipWaiting();
});

self.addEventListener('push', (event) => {
  if (event.data) {
    const data = event.data.json();
    const {
      badge,
      body,
      icon,
      image,
      actions,
      title,
      url,
      sent_at: sentAt,
    } = data;

    const options = {
      badge,
      body,
      actions,
      data: {
        actions,
        sentAt,
        url,
      },
      icon,
      image,
      requireInteraction: true
    };

    event.waitUntil(self.registration.showNotification(title, options));

    return fetch(serviceWorkerRoutes.measurements, {
      ...requestParams,
      body: JSON.stringify({
        indicator: 'PUSH_NOTIFICATION_DISPLAYED',
        sentAt,
      })
    });
  }

  return fetch(serviceWorkerRoutes.measurements, {
    ...requestParams,
    body: JSON.stringify({ indicator: 'PUSH_NOTIFICATION_DATA_MISSING' })
  });
});

self.addEventListener('notificationclick', (event) => {
  const { notification } = event;
  const hasActions = event.action && notification.data && notification.data.actions;
  let { url } = notification.data;

  notification.close();

  if (hasActions) {
    const action = notification.data.actions.find((item) => item.action === event.action);
    url = action ? action.url : url;
  }

  // eslint-disable-next-line no-undef
  const promiseChain = clients.openWindow(url);
  event.waitUntil(promiseChain);

  return fetch(serviceWorkerRoutes.measurements, {
    ...requestParams,
    body: JSON.stringify({
      indicator: 'PUSH_NOTIFICATION_CLICKED',
      action: event.action,
      sentAt: notification.data && notification.data.sentAt
    })
  });
});

self.addEventListener('pushsubscriptionchange',
  () => fetch(serviceWorkerRoutes.measurements, {
    ...requestParams,
    body: JSON.stringify({
      indicator: 'PUSH_NOTIFICATION_SUBSCRIPTION_CHANGED',
      sentAt: new Date().toISOString()
    })
  }));

self.addEventListener('notificationclose',
  (event) => fetch(serviceWorkerRoutes.measurements, {
    ...requestParams,
    body: JSON.stringify({
      indicator: 'PUSH_NOTIFICATION_CLOSED',
      sentAt: event.notification.data && event.notification.data.sentAt
    })
  }));