我无法在 Web 应用程序中使用 iPhone 检索 fcm 令牌
这是一个Linux服务器,使用Mysql,PHP 7.2并且没有Jquery。 Iḿ 以 Firebase Web Cloud Messaging 为例,适用于 PC 和移动 Android。但不适用于 IOS 浏览器
<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-messaging.js"></script>
<script>
var firebaseConfig = {
apiKey: "xxasdasdasdasdasdasdasdas",
authDomain: "projetono.firebaseapp.com",
databaseURL: "https://dsadsa-gds.firebaseio.com",
projectId: "dsadas-gds",
storageBucket: "",
messagingSenderId: "432423",
appId: "1:dffewfewfewfew:web:937953e7e514f066"
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.usePublicVapidKey("23432432432432423fewfewfew-fDfKw");
messaging.requestPermission().then(function(){
console.log('Have Permission');
return messaging.getToken();
}).then(function(token){
console.log(token);
document.write(token);
//var url = "https://api.whatsapp.com/send?phone=5511984314366" + "&text=" + token;
//window.open(url);
})
.catch(function(err){
document.write('Erro' + err);
console.log('Erro' + err)
});
messaging.onMessage(function(payload) {
console.log(payload.data);
data = payload.data;
navigator.serviceWorker.ready.then(function(registration) {
registration.showNotification(data.titulo, {
body: data.mensagem,
badge: data.badge,//'/m/public/img/gds_badge.png',
icon: data.icon,//'/m/public/img/carrinhocompras.png',
vibrate: data.vibrate// [200, 100, 200, 100, 200, 100, 200],
});
});
//console.log('Message received. ', payload);
// ...
});
我想在页面上显示身份令牌。 在命令文档中.write(令牌(
我用了 try - catch in firebase.messaging(( 并返回 ' 此浏览器不支持所需的 API'