init method

  1. @override
Future<bool> init(
  1. dynamic backgroundMessageHandler(
    1. Map
    )?, [
  2. String? notificationChannel = "messages",
  3. bool loggerEnabled = false,
  4. bool askPermissions = true,
  5. bool serverLoggerEnabled = false,
  6. String? applicationId,
  7. bool enablePushOnForeground = true,
  8. String? environment,
])
override

Implementation

@override
Future<bool> init(Function(Map<dynamic, dynamic>)? backgroundMessageHandler,
    [String? notificationChannel = "messages",
    bool loggerEnabled = false,
    bool askPermissions = true,
    bool serverLoggerEnabled = false,
    String? applicationId,
    bool enablePushOnForeground = true,
    String? environment]) async {
  messageCallback = backgroundMessageHandler;
  methodChannel.setMethodCallHandler(_handle);
  print(
      "[PushedPlugin][iOS][Dart] init loggerEnabled=$loggerEnabled askPermissions=$askPermissions applicationId=$applicationId environment=$environment");
  var result = await methodChannel.invokeMethod<String>('init', {
    "log": loggerEnabled,
    "serverlog": serverLoggerEnabled,
    "enablePushOnForeground": enablePushOnForeground,
    if (applicationId != null && applicationId.isNotEmpty)
      "applicationId": applicationId,
    if (environment != null && environment.isNotEmpty) "environment": environment,
  });
  if (result != "") {
    final safeResult = result ?? "";
    final tokenPrefix = safeResult.substring(
        0, safeResult.length > 8 ? 8 : safeResult.length);
    print("[PushedPlugin][iOS][Dart] init success tokenPrefix=$tokenPrefix");
    if (askPermissions) {
      await methodChannel
          .invokeMethod<bool>('requestNotificationPermissions');
    }
    FlutterPushedMessagingPlatform.pushToken = result;
    FlutterPushedMessagingPlatform.status = ServiceStatus.active;
    return true;
  }
  return false;
}