Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Messaging on IOS web browsers

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);
        });
like image 808
Sahib Huseynov Avatar asked Oct 21 '18 15:10

Sahib Huseynov


People also ask

Does Firebase Cloud Messaging work on iOS?

For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.

Does FCM work on Safari?

FCM doesn't support Safari browser.

Does Firebase messaging work on iOS simulator?

'FCM does not work on the iOS simulator, you must test them using a real device. This is a restriction enforced by Apple.

Can FCM send notification to iOS?

Once your client app is installed on a device, it can receive messages through the FCM APNs interface. You can immediately start sending notifications to user segments with the Notifications composer, or messages built on your application server.


1 Answers

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:

  • Push notifications in Apple Safari with FCM
  • ReactJS - FCM not working in safari browser
  • the Firebase Cloud Messaging for web documentation
  • the caniuse.com page for the push API
like image 116
Frank van Puffelen Avatar answered Nov 15 '22 10:11

Frank van Puffelen