简体   繁体   English

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

[英]I can't retrieve fcm token using Iphone in a web application

I can't retrieve fcm token using Iphone in a web application 我无法在Web应用程序中使用Iphone检索fcm令牌

This is a Linux Server, with Mysql , PHP 7.2 and not have Jquery. 这是具有Mysql,PHP 7.2且没有Jquery的Linux服务器。 Iḿ using the example of Firebase Web Cloud Messaging and works on PC and Mobile Android. 我以Firebase Web Cloud Messaging为例,可在PC和Mobile Android上使用。 But not work on IOS browsers 但不适用于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);
        // ...
    });

I want to show the idtoken on the page. 我想在页面上显示idtoken。 in command document.write(token) 在命令document.write(token)中

我用过try-catch firebase.messaging()并返回'此浏览器不支持API的必需'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM