小编Joh*_*n M的帖子

无法让 click_action 使用 Web 应用程序/PWA 处理 FCM 通知

我试图让我的“click_action”将用户带到我发送给客户端的通知上的特定 URL,但无论我做什么,它要么不执行任何操作(桌面),要么只是打开 PWA(android)。消息传输正常(在 Chrome 控制台中检查),但点击似乎不起作用。

\n\n

我的服务人员中有以下内容,是从各个地方抄来的,包括本网站上提供的其他答案:

\n\n
importScripts(\'https://www.gstatic.com/firebasejs/7.14.3/firebase-app.js\');\nimportScripts(\'https://www.gstatic.com/firebasejs/7.14.3/firebase-messaging.js\');\n// importScripts(\'/__/firebase/init.js\');\n\n/* An empty service worker!  */\nself.addEventListener(\'fetch\', function(event) {\n  /* An empty fetch handler! */\n});\n\n   var firebaseConfig = {\n//REDACTED\n  };\n  // Initialize Firebase\n  firebase.initializeApp(firebaseConfig);\n\n const messaging = firebase.messaging();\n\nmessaging.setBackgroundMessageHandler(function(payload) {\n  console.log(\'[firebase-messaging-sw.js] Received background message \', payload);\n  // Customize notification here\n\n\n  notificationTitle = payload.notification.title;\n  notificationOptions = {\n    body: payload.notification.body,\n    icon: payload.notification.icon,\n    click_action: payload.notification.click_action\n  };\n\n  return self.registration.showNotification(notificationTitle,\n    notificationOptions);\n});\n\nself.addEventListener(\'notificationclick\', function(event) {\n    let url = event.notification.click_action;\n// I\'ve also added a data.click_action field in my JSON notification, and …
Run Code Online (Sandbox Code Playgroud)

action click progressive-web-apps firebase-cloud-messaging

7
推荐指数
2
解决办法
9547
查看次数