Firebase Messaging on IOS web browsers

Viewed 6234

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);
        });
1 Answers
Related