簡體   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