Konsola git

firebase::messaging

Firebase Cloud Messaging API.

Summary

Firebase Cloud Messaging allows you to send data from your server to your users' devices, and receive messages from devices on the same connection if you're using a XMPP server.

The FCM service handles all aspects of queueing of messages and delivery to client applications running on target devices.

Enumerations

Error{
  kErrorNone = 0,
  kErrorFailedToRegisterForRemoteNotifications,
  kErrorInvalidTopicName,
  kErrorNoRegistrationToken,
  kErrorUnknown
}
enum
Error code returned by Firebase Cloud Messaging C++ functions.

Functions

Initialize(const App & app, Listener *listener)
Initialize Firebase Cloud Messaging.
Initialize(const App & app, Listener *listener, const MessagingOptions & options)
Initialize Firebase Cloud Messaging.
IsTokenRegistrationOnInitEnabled()
bool
Determines if automatic token registration during initalization is enabled.
RequestPermission()
Future< void >
Displays a prompt to the user requesting permission to display notifications.
RequestPermissionLastResult()
Future< void >
Gets the result of the most recent call to RequestPermission();.
Send(const Message & message)
void
Send an upstream ("device to cloud") message.
SetListener(Listener *listener)
Set the listener for events from the Firebase Cloud Messaging servers.
SetTokenRegistrationOnInitEnabled(bool enable)
void
Enable or disable token registration during initialization of Firebase Cloud Messaging.
Subscribe(const char *topic)
Future< void >
Subscribe to receive all messages to the specified topic.
SubscribeLastResult()
Future< void >
Gets the result of the most recent call to Unsubscribe();.
Terminate()
void
Terminate Firebase Cloud Messaging.
Unsubscribe(const char *topic)
Future< void >
Unsubscribe from a topic.
UnsubscribeLastResult()
Future< void >
Gets the result of the most recent call to Unsubscribe();.

Classes

firebase::messaging::Listener

Base class used to receive messages from Firebase Cloud Messaging.

firebase::messaging::PollableListener

A listener that can be polled to consume pending Messages.

Structs

firebase::messaging::AndroidNotificationParams

Data structure for parameters that are unique to the Android implementation.

firebase::messaging::Message

Data structure used to send messages to, and receive messages from, cloud messaging.

firebase::messaging::MessagingOptions

A class to configure the behavior of Firebase Cloud Messaging.

firebase::messaging::Notification

Used for messages that display a notification.

Enumerations

Error

 Error

Error code returned by Firebase Cloud Messaging C++ functions.

Properties
kErrorFailedToRegisterForRemoteNotifications

Permission to receive notifications was not granted.

kErrorInvalidTopicName

Topic name is invalid for subscription/unsubscription.

kErrorNoRegistrationToken

Could not subscribe/unsubscribe because there is no registration token.

kErrorNone

The operation was a success, no error occurred.

kErrorUnknown

Unknown error.

Functions

Initialize

InitResult Initialize(
  const App & app,
  Listener *listener
)

Initialize Firebase Cloud Messaging.

After Initialize is called, the implementation may call functions on the Listener provided at any time.

Details
Parameters
app
The Firebase App object for this application.
listener
A Listener object that listens for events from the Firebase Cloud Messaging servers.
Returns
kInitResultSuccess if initialization succeeded, or kInitResultFailedMissingDependency on Android if Google Play services is not available on the current device.

Initialize

InitResult Initialize(
  const App & app,
  Listener *listener,
  const MessagingOptions & options
)

Initialize Firebase Cloud Messaging.

After Initialize is called, the implementation may call functions on the Listener provided at any time.

Details
Parameters
app
The Firebase App object for this application.
listener
A Listener object that listens for events from the Firebase Cloud Messaging servers.
options
A set of options that configure the initialzation behavior of Firebase Cloud Messaging.
Returns
kInitResultSuccess if initialization succeeded, or kInitResultFailedMissingDependency on Android if Google Play services is not available on the current device.

IsTokenRegistrationOnInitEnabled

bool IsTokenRegistrationOnInitEnabled()

Determines if automatic token registration during initalization is enabled.

Details
Returns
true if auto token registration is enabled and false if disabled.

RequestPermission

Future< void > RequestPermission()

Displays a prompt to the user requesting permission to display notifications.

The permission prompt only appears on iOS. If the user has already agreed to allow notifications, no prompt is displayed and the returned future is completed immediately.

Details
Returns
A future that completes when the notification prompt has been dismissed.

RequestPermissionLastResult

Future< void > RequestPermissionLastResult()

Gets the result of the most recent call to RequestPermission();.

Details
Returns
Result of the most recent call to RequestPermission().

Send

void Send(
  const Message & message
)

Send an upstream ("device to cloud") message.

You can only use the upstream feature if your FCM implementation uses the XMPP-based Cloud Connection Server. The current limits for max storage time and number of outstanding messages per application are documented in the FCM Developers Guide.

Details
Parameters
message
The message to send upstream.

SetListener

Listener * SetListener(
  Listener *listener
)

Set the listener for events from the Firebase Cloud Messaging servers.

A listener must be set for the application to receive messages from the Firebase Cloud Messaging servers. The implementation may call functions on the Listener provided at any time.

Details
Parameters
listener
A Listener object that listens for events from the Firebase Cloud Messaging servers.
Returns
Pointer to the previously set listener.

SetTokenRegistrationOnInitEnabled

void SetTokenRegistrationOnInitEnabled(
  bool enable
)

Enable or disable token registration during initialization of Firebase Cloud Messaging.

This token is what identifies the user to Firebase, so disabling this avoids creating any new identity and automatically sending it to Firebase, unless consent has been granted.

If this setting is enabled, it triggers the token registration refresh immediately. This setting is persisted across app restarts and overrides the setting "firebase_messaging_auto_init_enabled" specifi