Flutter google 移动广告仅在 IOS 上展示测试广告

Flutter google mobile ads only shows test ads on IOS

我有以下广告库

import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:my_app/data/api/constants.dart';

class AdMobRepository {
  late String liveBannerAdId;
  late String liveInterstitualAdId;
  late String liveRewardedAdId;

  AdMobRepository() {
    if (Platform.isAndroid) {
      liveBannerAdId = Constants.androidBannedAdId;
      liveInterstitualAdId = Constants.androidInterstitualAdId;
      liveRewardedAdId = Constants.androidRewardedAdId;
    } else if (Platform.isIOS) {
      liveBannerAdId = Constants.iosBannerAdId;
      liveInterstitualAdId = Constants.iosInterstitualAdId;
      liveRewardedAdId = Constants.iosRewardedAdId;
    } else {
      liveBannerAdId = "";
      liveInterstitualAdId = "";
      liveRewardedAdId = "";
    }
  }

  BannerAd getBannerAd({
    required AdSize size,
    void Function(Ad, LoadAdError)? onFailedLoad,
    void Function(Ad)? onLoad,
    void Function(Ad)? onAdOpened,
    void Function(Ad)? onAdImpression,
  }) {
    return BannerAd(
      adUnitId: kReleaseMode ? liveBannerAdId : BannerAd.testAdUnitId,
      request: AdRequest(),
      size: size,
      listener: BannerAdListener(
        onAdFailedToLoad: onFailedLoad ?? onFailedLoadFallback,
        onAdLoaded: onLoad,
        onAdImpression: onAdImpression,
        onAdOpened: onAdOpened,
      ),
    );
  }

  void onFailedLoadFallback(Ad ad, LoadAdError error) {
    ad.dispose();
  }

  void getInterstitualAd({required void Function(LoadAdError) onFailedLoad, void Function(InterstitialAd)? onLoad}) {
    InterstitialAd.load(
      adUnitId: kReleaseMode ? liveInterstitualAdId : InterstitialAd.testAdUnitId,
      request: AdRequest(),
      adLoadCallback: InterstitialAdLoadCallback(
        onAdLoaded: onLoad ?? onInterstitialAdLoadedFallback,
        onAdFailedToLoad: onFailedLoad,
      ),
    );
  }

  void onInterstitialAdLoadedFallback(InterstitialAd ad) {
    ad.fullScreenContentCallback = FullScreenContentCallback(
        onAdDismissedFullScreenContent: (ad) => ad.dispose(), onAdFailedToShowFullScreenContent: (ad, error) => ad.dispose());
  }

  void getRewardAd({required String userId, required void Function(LoadAdError) onFailedLoad, void Function(RewardedAd)? onLoad}) {
    RewardedAd.load(
      adUnitId: kReleaseMode ? liveRewardedAdId : RewardedAd.testAdUnitId,
      request: AdRequest(),
      rewardedAdLoadCallback: RewardedAdLoadCallback(
        onAdLoaded: onLoad ?? onRewardedAdLoadedFallback,
        onAdFailedToLoad: onFailedLoad,
      ),
      serverSideVerificationOptions: ServerSideVerificationOptions(userId: userId),
    );
  }

  void onRewardedAdLoadedFallback(RewardedAd ad) {
    ad.fullScreenContentCallback = FullScreenContentCallback(
        onAdDismissedFullScreenContent: (ad) => ad.dispose(), onAdFailedToShowFullScreenContent: (ad, error) => ad.dispose());
  }
}

我有以下横幅广告小部件

class MyBannerAd extends StatefulWidget {

  const MyBannerAd();

  @override
  _MyBannerAdState createState() => _MyBannerAdState();
}

class _MyBannerAdState extends State<MyBannerAd> {
  late AdSize adSize;
  late AdMobRepository adRepository;
  late AnalyticsRepository analyticsRepository;
  bool adLoaded = false;
  BannerAd? anchoredBanner;

  @override
  void initState() {
    super.initState();
    adRepository = context.read<AdMobRepository>();
    analyticsRepository = context.read<AnalyticsRepository>();

    if (SizerUtil.deviceType != DeviceType.mobile && SizerUtil.orientation == Orientation.portrait) {
      adSize = AdSize.leaderboard;
    } else {
      adSize = AdSize.largeBanner;
    }

    final bannerAd = adRepository.getBannerAd(
      size: adSize,
      onFailedLoad: (ad, error) {
        print('banner ad failed to load: $error');
        ad.dispose();
      },
      onLoad: (ad) {
        setState(() {
          adLoaded = true;
          anchoredBanner = ad as BannerAd?;
        });
      },
      onAdImpression: (_) {
        analyticsRepository.sendBannerAdShownEvent();
      },
      onAdOpened: (_) {
        analyticsRepository.sendBannerAdClickEvent();
      },
    );

    bannerAd.load();
  }

  @override
  void dispose() {
    super.dispose();
    anchoredBanner?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<SubscriptionBloc, SubscriptionState>(
      builder: (context, state) {
        final isLoaded = !adLoaded;

        if (isLoaded || state.hasSubscribed || anchoredBanner == null) return SizedBox.shrink();

        return Container(
          color: Colors.transparent,
          width: anchoredBanner!.size.width.toDouble(),
          height: anchoredBanner!.size.height.toDouble(),
          child: Center(
            child: Container(
              color: Colors.white,
              child: AdWidget(
                ad: anchoredBanner!,
              ),
            ),
          ),
        );
      },
    );
  }
}

但在 IOS 上它始终显示测试广告。当应用程序使用 flutter build ios --release 的 flutter 发布模式构建时,这怎么可能?该应用程序目前正在审核中,我认为只要这些广告在应用程序商店上架,它们就不再是测试广告了。

但是 Apple 向我们发送了以下消息

We noticed that your app or its screenshots include test advertisements. Apps or metadata items that include features that are for test or demonstration purposes are not appropriate for the App Store.

Next Steps

To resolve this issue, please revise your app to complete, remove, or fully configure any partially implemented features. Please ensure your screenshots do not include any images of demo, test, or other incomplete content

那么我该如何去掉测试广告呢?我错过了一些 XCode 设置还是?

我正在使用

flutter: 2.5.3
google_mobile_ads: ^0.13.4

我还将 GADApplicationIdentifier 添加到我的 info.plist

<key>GADApplicationIdentifier</key>
<string>{here I have the app Id}</string>

我正在使用 testflight 构建的真实设备上进行测试

旁注:

在 admob 设置中我添加了以下测试 IDFA

00000000-0000-0000-0000-000000000000

这似乎适用于所有 IOS 设备上的测试广告。

您无需更改任何代码。

Next Steps

To resolve this issue, please revise your app to complete, remove, or fully configure any partially implemented features. Please ensure your screenshots do not include any images of demo, test, or other incomplete content

要解决上述拒绝,您需要做的就是从您的屏幕截图中删除横幅广告并重新提交审核。

原来我需要从 admob 的测试设置中删除 00000000-0000-0000-0000-000000000000。之后我不再收到测试广告,但我现在收到发布版本中的广告。