Flutter
An example application is available to show basic usage of the library.
Add the following code to your pubspec.yaml.
unifiedpush: ^5.0.0
You can ignore instances if you don’t need to handle multiple connections.
UnifiedPush.initialize(
onNewEndpoint: onNewEndpoint,
onRegistrationFailed: onRegistrationFailed,
onUnregistered: onUnregistered,
onMessage: onMessage,
);
void onNewEndpoint(String endpoint, String instance) {
// You should send the endpoint to your application server
// and sync for missing notifications.
}
void onRegistrationFailed(String instance) {}
void onUnregistered(String instance) {}
void onMessage(Uint8List message, String instance) {}
To register for receiving push services you have two options, after initializing:
// inform the library that you would like to unregister from receiving push messages
UnifiedPush.unregister(
instance // Optionnal String, to get multiple endpoints (one per instance)
);
// You won't receive onUnregistered for this instance
(From the application server)
To send a message to an application you need the “endpoint”. You get it in the onNewEndpoint method once it is available. You can then use it to send a message using for example curl. The POST body is the message received by the function onMessage.
curl -X POST "$endpoint" --data "Any message body that is desired."
On the Android side, you will need to import and declare the embedded distributor. Please refer to Embedded FCM Distributor for more information.