initialize static method

Future<bool> initialize({
  1. void onNewEndpoint(
    1. PushEndpoint endpoint,
    2. String instance
    )?,
  2. void onRegistrationFailed(
    1. FailedReason reason,
    2. String instance
    )?,
  3. void onUnregistered(
    1. String instance
    )?,
  4. void onMessage(
    1. PushMessage message,
    2. String instance
    )?,
  5. void onTempUnavailable(
    1. String instance
    )?,
  6. String? linuxDBusName,
})

Initialize the different event listener.

Returns Future<true> if a distributor is already registered, Future<false> else;

  • onNewEndpoint Invoked when a new endpoint is to be used for sending push messages
  • onRegistrationFailed Invoked when the registration is not possible, eg. no network, depending on the reason, you can try to register again directly.
  • onUnregistered Invoked when this registration is unregistered by the distributor and won't receive push messages anymore
  • onMessage Invoked when a new message is received
  • onTempUnavailable Invoked 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;
}