【问题标题】:Interstitial ads not showing in Flutter插页式广告未在 Flutter 中展示
【发布时间】:2020-01-06 12:13:49
【问题描述】:

我正在使用这个包:https://pub.dev/packages/firebase_admob

一切设置正确,正常横幅显示。我的问题只出现在插页式广告上:

import 'package:firebase_admob/firebase_admob.dart';

BannerAd myBanner = BannerAd(
  adUnitId: BannerAd.testAdUnitId,
  size: AdSize.smartBanner,
  listener: (MobileAdEvent event) {
    print("BannerAd event is $event");
  },
);

InterstitialAd myInterstitial = InterstitialAd(
  adUnitId: 'ca-app-pub-MYID',
  listener: (MobileAdEvent event) {
    print("InterstitialAd event is $event");
  },
);

class Ads {
  static showBanner() {
    myBanner
      // typically this happens well before the ad is shown
      ..load()
      ..show(
        // Positions the banner ad 60 pixels from the bottom of the screen
        anchorOffset: 0.0,
        // Positions the banner ad 10 pixels from the center of the screen to the right
        horizontalCenterOffset: 0.0,
        // Banner Position
        anchorType: AnchorType.bottom,
      );
  }

  static showInterstitial() {
    myInterstitial
      ..load()
      ..show(
        anchorType: AnchorType.bottom,
        anchorOffset: 0.0,
        horizontalCenterOffset: 0.0,
      );
  }
}

final Ads ads = Ads();

为了展示它,我这样做了:Ads.showInterstitial(); 但它从未展示过。

如果我再次尝试调用它,错误会破坏应用程序。

我不在我的应用上使用 Statefull 小部件

【问题讨论】:

  • 你在哪里称呼它?
  • 小部件构建内部
  • 它是假的,在initstate中调用它
  • 我不在我的应用程序上使用 Stateful 小部件。我使用全球提供商
  • 我确实在发布 apk 上显示,但在开发模式下没有显示

标签: flutter admob flutter-dependencies firebase-admob


【解决方案1】:

我认为您必须添加设备的 ID,作为 testDevice 才能看到那里的广告。

添加一个targetingInfo 属性,您可以在其中添加设备的ID。

MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
  testDevices: <String>["*add id of your device here*"], // Android emulators are considered test devices
);

在创建插页式字段时,添加 targetInfo 属性,如 Readme of the plugin page 中所述。

InterstitialAd myInterstitial = InterstitialAd(
  // Replace the testAdUnitId with an ad unit id from the AdMob dash.
  // https://developers.google.com/admob/android/test-ads
  // https://developers.google.com/admob/ios/test-ads
  adUnitId: InterstitialAd.testAdUnitId,
  targetingInfo: targetingInfo, // <--- here
  listener: (MobileAdEvent event) {
    print("InterstitialAd event is $event");
  },
);

【讨论】:

  • op 仅表示插页式广告的问题。身份证没有问题。
猜你喜欢
  • 1970-01-01
  • 2021-11-10
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多