繁体   English   中英

Flutter 谷歌移动广告仅在 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的发布模式构建应用程序时,怎么会这样? 该应用程序目前正在审核中,我认为这些广告只要在应用程序商店上发布就不再是测试广告。

但苹果向我们发送了以下信息

我们注意到您的应用或其屏幕截图包含测试广告。 包含用于测试或演示目的的功能的应用程序或元数据项不适用于 App Store。

下一步

要解决此问题,请修改您的应用程序以完成、删除或完全配置任何部分实现的功能。 请确保您的屏幕截图不包含任何演示、测试或其他不完整内容的图像

那么如何摆脱测试广告呢? 我错过了一些 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 设备上的测试广告。

您无需进行任何代码更改。

下一步

要解决此问题,请修改您的应用程序以完成、删除或完全配置任何部分实现的功能。 请确保您的屏幕截图不包含任何演示、测试或其他不完整内容的图像

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM