简体   繁体   中英

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

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

This is a Linux Server, with Mysql , PHP 7.2 and not have Jquery. Iḿ using the example of Firebase Web Cloud Messaging and works on PC and Mobile Android. But not work on IOS browsers

<!-- 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. in command document.write(token)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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