Notes

Cloud Messaging

See the Firebase Cloud Messaging docs for webarrow-up-right.

manifest.json

{
  "gcm_sender_id": "103953800507"
}

Request permission in browser

// index.html
const messaging = firebase.messaging();
messaging
  .requestPermission()
  .then(function() {
    // Get Instance ID token. Initially this makes a network call, once retrieved
    // subsequent calls to getToken will return from cache.
    messaging.getToken()
    .then(function(currentToken) {
      if (currentToken) {
        sendTokenToServer(currentToken);
        updateUIForPushEnabled(currentToken);
      } else {
        // Show permission request.
        console.log('No Instance ID token available. Request permission to generate one.');
        // Show permission UI.
        updateUIForPushPermissionRequired();
        setTokenSentToServer(false);
      }
    })
    .catch(function(err) {
      console.log('An error occurred while retrieving token. ', err);
      showToken('Error retrieving Instance ID token. ', err);
      setTokenSentToServer(false);
    });
  }
  .catch(function(err) {
    console.log('Unable to get permission to notify.', err);
  });

Monitor token refresh

Catch messages when page is in foreground

Create serviceWorker

You need a serviceWorker to listen for messages in the background

Send message to single recipient

Send multi-cast message

Send device-group message

See managing device groupsarrow-up-right

Send topic message

See managing device groupsarrow-up-right

Send to condition

Conditions support only two operations per expression

Message options

Subscribe to topic

Subscribe to topic

Unsubscribe to topic

Last updated