The function that will receive the distributor messages.
This function will always receive an object with the properties action
and data
:
data
: The data sent from the distributor. Varies depending on the action
property.action
: The action that was performed by the distributor. Can be one of the following:"message"
: A push notification was received. Data for this type is MessagePayload.
The text in data.message
will contain the JSON-encoded payload of the push notification if data.decrypted
is true
.
Otherwise, it will contain the raw encrypted payload."registered"
: The device has been registered with a distributor. Data for this type is RegisteredPayload. This is the data that is needed for the backend to send a push notification to a specific device."registrationFailed"
: The device failed to register with a distributor. Data for this type is RegistrationFailedPayload."unregistered"
: The device has been unregistered from a distributor. Data for this type is UnregisteredPayload."error"
: An error occurred while receiving a message from a distributor. Data for this type is ErrorPayload.
Subscribe to the messages sent from the distributor background service. This callback will be called whenever the distributor sends a message to the device. It will not run if the app is terminated but notifications will still be delivered even if this callback is not registered. It will also receive error messages created when displaying notifications on the background service.