getGcmKey static method

Future<String> getGcmKey()

Implementation

static Future<String> getGcmKey() async {
  try {
    if (Platform.isIOS) {
      doPrint('Waiting for APNS token on iOS...');
      final String? apnsToken = await _firebaseMessaging.getAPNSToken();
      if (apnsToken != null) {
        doPrint('APNS Token found: $apnsToken');
      } else {
        doPrint('APNS token is null. Push notifications might not work on iOS. Please ensure Push Notifications capability is added in Xcode.');
      }
    }
    final String? token = await _firebaseMessaging.getToken();
    if (token != null) {
      doPrint('GCM Key (FCM Token) found: $token');
      return token;
    }
    return 'no-token-available';
  } catch (e) {
    doPrint('Could not get GCM key: $e');
    return 'error-fetching-token';
  }
}