Firebase Messaging on IOS web browsers
Asked Answered
D

2

7

Firebase messaging push notifications work Desktop and Android web browsers without any problem but when I tested it on IOS devices it doesn't matter which browser I used, notifications and .getToken() method not working. My JavaScript code is that:

if ('Notification' in window) {
    var messaging = firebase.messaging();
    if (Notification.permission === 'granted') {
        subscribe();
    }

    $('#notify').on('click', function () {
        subscribe();
    });
}

function subscribe() {
    // запрашиваем разрешение на получение уведомлений
    messaging.requestPermission()
        .then(function () {
            // получаем ID устройства
            return messaging.getToken()
                .then(function (currentToken) {
                    console.log(currentToken);

                    if (currentToken) {
                        sendTokenToServer(currentToken);
                    } else {
                        console.warn('Не удалось получить токен.');
                        setTokenSentToServer(false);
                    }
                })
                .catch(function (err) {
                    console.warn('При получении токена произошла ошибка.', err);
                    setTokenSentToServer(false);
                });
        })
        .catch(function (err) {
            console.warn('Не удалось получить разрешение на показ уведомлений.', err);
        });
Disenchant answered 21/10, 2018 at 15:45 Comment(0)
M
9

All browsers on iOS are essentially wrappers around WebKit (the browser engine that is used in Safari), so they inherit most of their features and limitations from there. Unfortunately Safari still doesn't support the Web Push API, that is required for Firebase Cloud Messaging.

Also see:

Mccowyn answered 21/10, 2018 at 16:8 Comment(0)
C
1

Web push notification works on Home Screen web apps in iOS 16.4 or later.

Also see: Sending web push notifications in web apps, Safari, and other browsers

Cretaceous answered 26/7, 2023 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.