registerTokenForPushNotification static method

Future<void> registerTokenForPushNotification(
  1. String token, {
  2. required dynamic onSuccess(
    1. String response
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?,
})

Registers the obtained FCM Token which will be used by the CometChat server to send message via push notification.

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<void> registerTokenForPushNotification(String token, {required Function(String response)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('registerTokenForPushNotification', {
      'token': token,
    });
    if (onSuccess != null) onSuccess(result);
  } on PlatformException catch (platformException) {
    if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
  } catch (e) {
    debugPrint("Error: $e");
    if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
  }
}