initialize static method
- void onNewEndpoint(
- PushEndpoint endpoint,
- String instance
- void onRegistrationFailed(
- FailedReason reason,
- String instance
- void onUnregistered(
- String instance
- void onMessage(
- PushMessage message,
- String instance
- String? linuxDBusName,
Initialize the different event listener.
Returns Future<true> if a distributor is already registered,
Future<false> else;
onNewEndpointInvoked when a new endpoint is to be used for sending push messagesonRegistrationFailedInvoked when the registration is not possible, eg. no network, depending on the reason, you can try to register again directly.onUnregisteredInvoked when this registration is unregistered by the distributor and won't receive push messages anymoreonMessageInvoked when a new message is receivedonTempUnavailableInvoked when the distributor backend is temporary unavailable.
You can ignore instances if you don't use them.
Implementation
static Future<bool> initialize({
void Function(PushEndpoint endpoint, String instance)? onNewEndpoint,
void Function(FailedReason reason, String instance)? onRegistrationFailed,
void Function(String instance)? onUnregistered,
void Function(PushMessage message, String instance)? onMessage,
void Function(String instance)? onTempUnavailable,
String? linuxDBusName,
}) async {
if (Platform.isLinux) {
UnifiedPushPlatform.instance.setDBusName(linuxDBusName);
}
await UnifiedPushPlatform.instance.initializeCallback(
onNewEndpoint: (PushEndpoint e, String i) async =>
onNewEndpoint?.call(e, i),
onRegistrationFailed: (FailedReason r, String i) async =>
onRegistrationFailed?.call(r, i),
onUnregistered: (String i) async => onUnregistered?.call(i),
onMessage: (PushMessage m, String i) async => onMessage?.call(m, i));
await UnifiedPushPlatform.instance.initializeOnTempUnavailable(
onTempUnavailable: (String i) async => onTempUnavailable?.call(i)
);
return await UnifiedPush.getDistributor() != null;
}