前往主控台

The Firebase Messaging service interface.

Do not call this constructor directly. Instead, use firebase.messaging().

See Set Up a JavaScript Firebase Cloud Messaging Client App for a full guide on how to use the Firebase Messaging service.

Index

Methods

deleteToken

  • deleteToken(token: string): Promise<boolean>
  • To forceably stop a registration token from being used, delete it by calling this method.

    Parameters

    • token: string

      The token to delete.

    Returns Promise<boolean>

    The promise resolves when the token has been successfully deleted.

getToken

  • getToken(): Promise<string | null>
  • After calling requestPermission() you can call this method to get an FCM registration token that can be used to send push messages to this user.

    Returns Promise<string | null>

    The promise resolves if an FCM token can be retrieved. This method returns null if the current origin does not have permission to show notifications.

onMessage

  • onMessage(nextOrObserver: firebase.NextFn<any> | Observer<any>, error?: firebase.ErrorFn, completed?: firebase.CompleteFn): firebase.Unsubscribe
  • When a push message is received and the user is currently on a page for your origin, the message is passed to the page and an onMessage() event is dispatched with the payload of the push message.

    NOTE: These events are dispatched when you have called setBackgroundMessageHandler() in your service worker.

    Parameters

    • nextOrObserver: firebase.NextFn<any> | Observer<any>
    • Optional error: firebase.ErrorFn
    • Optional completed: firebase.CompleteFn

    Returns firebase.Unsubscribe

    To stop listening for messages execute this returned function.

onTokenRefresh

  • onTokenRefresh(nextOrObserver: firebase.NextFn<any> | Observer<any>, error?: firebase.ErrorFn, completed?: firebase.CompleteFn): firebase.Unsubscribe
  • You should listen for token refreshes so your web app knows when FCM has invalidated your