initialize method

Future<bool?> initialize(
  1. DarwinInitializationSettings initializationSettings, {
  2. DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse,
  3. DidReceiveBackgroundNotificationResponseCallback? onDidReceiveBackgroundNotificationResponse,
})

Initializes the plugin.

Call this method on application before using the plugin further.

Initialisation may also request notification permissions where users will see a permissions prompt. This may be fine in cases where it's acceptable to do this when the application runs for the first time. However, if your application needs to do this at a later point in time, set the DarwinInitializationSettings.requestAlertPermission, DarwinInitializationSettings.requestBadgePermission and DarwinInitializationSettings.requestSoundPermission and DarwinInitializationSettings.requestProvisionalPermission values to false. requestPermissions can then be called to request permissions when needed.

The onDidReceiveNotificationResponse callback is fired when the user selects a notification or notification action that should show the application/user interface. application was running. To handle when a notification launched an application, use getNotificationAppLaunchDetails. For notification actions that don't show the application/user interface, the onDidReceiveBackgroundNotificationResponse callback is invoked on a background isolate. Functions passed to the onDidReceiveBackgroundNotificationResponse callback need to be annotated with the @pragma('vm:entry-point') annotation to ensure they are not stripped out by the Dart compiler.

Implementation

Future<bool?> initialize(
  DarwinInitializationSettings initializationSettings, {
  DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse,
  DidReceiveBackgroundNotificationResponseCallback?
      onDidReceiveBackgroundNotificationResponse,
}) async {
  _onDidReceiveNotificationResponse = onDidReceiveNotificationResponse;
  _onDidReceiveLocalNotification =
      initializationSettings.onDidReceiveLocalNotification;
  _channel.setMethodCallHandler(_handleMethod);

  final Map<String, Object> arguments = initializationSettings.toMap();

  _evaluateBackgroundNotificationCallback(
      onDidReceiveBackgroundNotificationResponse, arguments);

  return await _channel.invokeMethod('initialize', arguments);
}