syncAndFetchBannersiOS static method

Future<List<AdItem>> syncAndFetchBannersiOS(
  1. String bannerSize,
  2. String bannerName
)

iOS-specific: Sync and fetch banners in a single call On iOS, syncBannerDetails returns ad items directly (not bannerId) Returns list of AdItems or empty list on error

Implementation

static Future<List<AdItem>> syncAndFetchBannersiOS(
  String bannerSize,
  String bannerName,
) async {
  try {
    final result =
        await _channel.invokeMethod<List<dynamic>>('syncBannerDetails', {
      'bannerSize': bannerSize,
      'bannerName': bannerName,
    });

    if (result == null) {
      return [];
    }

    // Convert List<dynamic> to List<AdItem>
    return result.map((item) {
      if (item is Map) {
        return AdItem.fromJson(Map<String, dynamic>.from(item));
      } else if (item is String) {
        final jsonMap = jsonDecode(item) as Map<String, dynamic>;
        return AdItem.fromJson(jsonMap);
      } else {
        throw FormatException('Invalid AdItem format: $item');
      }
    }).toList();
  } on PlatformException catch (e) {
    throw Exception('Failed to sync and fetch banners: ${e.message}');
  } on FormatException catch (e) {
    throw Exception('Failed to parse banner data: ${e.message}');
  }
}