registerDeviceToken method

Future<void> registerDeviceToken(
  1. String appCode
)

Registers this device's FCM token with the backend.

This allows the backend to send push notifications to this specific device. The method sends device information including OS version, device ID, model, and the Firebase token.

Parameters:

  • appCode: Application code for backend identification

Implementation

Future<void> registerDeviceToken(String appCode) async {
  if (!await hasNotificationPermission() || _deviceToken == null) return;

  final deviceInfo = SupaArchitecturePlatform.instance.deviceInfo;
  final deviceToken = DeviceNotificationToken(
    osVersion: deviceInfo.systemVersion,
    deviceId: deviceInfo.deviceUuid,
    deviceModel: deviceInfo.deviceModel,
    token: _deviceToken!,
    appCode: appCode,
  );

  try {
    await _notificationRepository.createToken(deviceToken);
  } catch (error) {
    debugPrint("Failed to register device token: ${error.toString()}");
  }
}