我无法在Web应用程序中使用Iphone检索fcm令牌

时间:2019-08-20 17:19:16

标签: javascript php firebase-cloud-messaging

我无法在Web应用程序中使用Iphone检索fcm令牌

这是一个Linux服务器,具有Mysql,PHP 7.2和没有Jquery。 我以Firebase Web Cloud Messaging为例,可在PC和Mobile 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);
        // ...
    });

我想在页面上显示idtoken。 在命令document.write(token)

1 个答案:

答案 0 :(得分:0)

我尝试过-在firebase.messaging()中捕获并返回 “此浏览器不支持API的必需项”