Push notifications in Apple Safari with FCM

2020-02-06 06:25发布

问题:

We implemented push notifications using FCM in chrome and firefox and it worked fine, but Safari doesn't support Service Workers which is mandatory for FCM.

Did anyone deal with this kind of issues? any suggestions?

回答1:

While Service Workers now work on Safari, they are not enough.

The documentation says:

The FCM JavaScript API lets you receive notification messages in web apps running in browsers that support the Push API. This includes the browser versions listed in this support matrix.

Safari doesn't support web push, which FCM relies on for browser support. So that means that Safari can't receive FCM notifications.



回答2:

I'm not sure about this new Safari and Service Workers situation, but I tried to implement FCM push-notifications in my iOS app and had to experience that you need an APN (Apple-Push-Notification) certificate first. I'm not sure if this is needed if you're working with Safari, but I could imagine that Apple also wants it's push notifications first to be redirected to the APN servers.



回答3:

Safari still does not support Web Push API, thus Firebase Cloud Messaging service.

Here is supported browsers in Firebase: https://firebase.google.com/support/guides/environments_js-sdk#browsers

I'd suggest using .isSupported() instead of other solutions.

if (firebase.messaging.isSupported())
    const messaging = firebase.messaging();
}

See the documentation for details on .isSupported().