[英]firebase messaging.getToken() return null
I am following this tutorial Set Up a JavaScript Firebase Cloud Messaging Client App .我正在关注本教程设置 JavaScript Firebase 云消息传递客户端应用程序。 When I ran the page for the first time, I clicked on "Block" rather than "Allow" when the page asked me to show notifications.
当我第一次运行页面时,当页面要求我显示通知时,我点击了“阻止”而不是“允许”。 After removing the site from the Chrome blocked list Turn notifications on or off ,
messaging.getToken()
always returns null
.从 Chrome 阻止列表中删除站点后打开或关闭通知,
messaging.getToken()
始终返回null
。
I tried messaging.deleteToken()
but this requires a valid (not null) token anyway.我尝试过
messaging.deleteToken()
但这无论如何都需要一个有效的(非空)令牌。
How to solve this?如何解决这个问题?
You must start a server in the folder of your project您必须在项目文件夹中启动服务器
php -S 127.0.0.1:8080
and access like this http://127.0.0.1:8080/并像这样访问http://127.0.0.1:8080/
It will NEVER work if you sign in from another folder like this http://127.0.0.1/miproyecto/ http://localhost/myproject/如果您从像这样的另一个文件夹登录http://127.0.0.1/miproyecto/ http://localhost/myproject/ ,它将永远不会工作
remember to create the file firebase-messaging-sw.js in the root https://firebase.google.com/docs/cloud-messaging/js/receive?hl=en-419记得在根https://firebase.google.com/docs/cloud-messaging/js/receive?hl=en-419 中创建文件 firebase-messaging-sw.js
Debes iniciar un servidor en la carpeta de tu proyecto Debes iniciar un servidor en la carta de tu proyecto
php -S 127.0.0.1:8080
y acceder así http://127.0.0.1:8080/ y 加入http://127.0.0.1:8080/
NUNCA funcionara si accedes desde otra carpeta así http://127.0.0.1/miproyecto/ http://localhost/miproyecto/ NUNCA funcionara si 加入 desde otra 地毯 así http://127.0.0.1/miproyecto/ http://localhost/miproyecto/
recuerda crear el archivo firebase-messaging-sw.js en la raiz https://firebase.google.com/docs/cloud-messaging/js/receive?hl=es-419 recuerda crear el archivo firebase-messaging-sw.js en la raiz https://firebase.google.com/docs/cloud-messaging/js/receive?hl=es-419
Don't forget to make a firebase-messaging-sw.js file in your root repo or public folder inside root repo .不要忘记在root repo或root repo 内的公共文件夹中创建 firebase-messaging-sw.js文件。 And then, open that file via your localhost server.
然后,通过本地主机服务器打开该文件。 Ex : localhost:5000/firebase-messaging-sw.js .
例如: localhost:5000/firebase-messaging-sw.js 。
If you still get an error page, you need to create manifest.json file.如果仍然出现错误页面,则需要创建manifest.json文件。 In this file, put your gcm_sender_id or messagingSenderID .
在这个文件中,把你的gcm_sender_id或messagingSenderID。
{
"gcm_sender_id" : "587997283287"
}
In my case, I can resolve this problem.就我而言,我可以解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.