registerPushTokenCallbackEvents method

  1. @override
Future<void> registerPushTokenCallbackEvents(
  1. dynamic onSetPushToken(
    1. String token
    )
)
override

Implementation

@override
Future<void> registerPushTokenCallbackEvents(
    Function(String token) onSetPushToken) async {
  _pushTokenSubscription?.cancel();
  try {
    await _configChannel.invokeMethod<bool>(
        SuperfineSdkChannelMethods.registerPushTokenListener);
    _pushTokenSubscription =
        pushTokenChannel.receiveBroadcastStream().listen((token) {
      if (token is String) {
        onSetPushToken.call(token);
      } else {
        print('Mismatch push token event type');
      }
    }, onError: (dynamic error) {
      print('Received error: ${error.message}');
    });
  } catch (e) {
    print("Error register push token listener: $e");
  }
}