Firebase, requestPermission;未捕获的语法错误:Web 云消息传递中出现意外令牌



我刚刚开始使用Firebase Web Cloud Messaging ,偶然发现了一个无法继续的问题。

云消息传递与Tizen Web应用程序(三星设备应用程序(集成,目标是使用云消息传递并接收消息。

控制台将"未捕获的语法错误:意外令牌"显示在.html文件中的一行。

这是代码停止/故障的地方:return.messaging.getToken((;

我需要如何解决这个问题?

我尝试使用此Firebase链接(此链接是文档的第一页(

此部分包含在内并写入.html

</body>
<!-- The core Firebase JS SDK is always required and must be listed first         -->
<
<script src="https://www.gstatic.com/firebasejs/6.4.0/firebase-app.js">               </script>
<!-- <script src="/__/firebase/6.4.0/firebase.js"></script> -->
<script
src="https://www.gstatic.com/firebasejs/6.4.0/firebase-messaging.js">         </script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "confidential information",
authDomain: "confidential information",
databaseURL: "confidential information",
projectId: "confidential information",
storageBucket: "",
messagingSenderId: "confidential information",
appId: "confidential information"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.usePublicVapidKey('!token!');

messaging.requestPermission()
.then(function() {
console.log('Have Permission');
return.messaging.getToken();
})
.then(function(token) {
console.log(token);
})
.catch(function(err) {
console.log('Error Occured.')

messaging.onMessage(function(payload) {
console.log('onMessage: ', payload);
});
</script>
</html>

必须包含在应用程序包中的.js文件

文件名: 火碱-消息-sw.js

importScripts('https://www.gstatic.com/firebasejs/6.4.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/6.4.0/firebase-       messaging.js');
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey : "confidential information",
authDomain : "confidential information",
databaseURL : "confidential information",
projectId : "confidential information",
storageBucket : "",
messagingSenderId : "confidential information",
appId : "confidential information"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const
messagin = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
const
title = "Hello World";
const
options = {
body : payload.data.status
};
// normal web browser api in displaying notifications
return self.registration.showNotification();
});

请参阅:

  • https://firebase.google.com/support/release-notes/js#cloud-messaging
  • https://developer.mozilla.org/ja/docs/Web/API/notification/requestPermission

已弃用的请求权限((。请改用本机浏览器 API Notification.requestPermission((。

无论如何,请尝试使用Notification.requestPermission().

相关内容

  • 没有找到相关文章

最新更新