Google AdMobs的奖励视频有时仅加载

时间:2019-10-04 12:22:18

标签: flutter admob rewardedvideoad admob-rewardedvideoad firebase-admob

我正在尝试在我的应用中实施广告。目前,我正在制作Google Ad Mobs奖励视频广告。我的问题是,在我第一次按下应加载广告的按钮后,出现了以下错误:

  

未处理的异常:PlatformException(ad_not_loaded,对于奖励视频显示失败,未加载广告,为空)

抛出

,但是如果我再按一次,它将正常工作。我已经附上了一些相关的代码

设置定位信息,加载广告并创建侦听器:

  @override
  void initState() {

    MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
        keywords: <String>['flutterio', 'beautiful apps'],
        contentUrl: 'https://flutter.io',
        childDirected: false,
    );

    RewardedVideoAd.instance.load(
        targetingInfo: targetingInfo,
        adUnitId: RewardedVideoAd.testAdUnitId);

    RewardedVideoAd.instance.listener =
        (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
      if (event == RewardedVideoAdEvent.rewarded) {
        Navigator.push(
                      context,
                      this.route);
      }
      else if(event == RewardedVideoAdEvent.failedToLoad){
        Navigator.push(
                      context,
                      this.route);
      }
    };
    super.initState();
  }

启动广告的按钮(位于同一类的build方法中):

              GestureDetector(
                child: AdButton(theme.wopGH, "Gratis spielen"),
                onTap: () {
                  RewardedVideoAd.instance.show();
                },
              ),

1 个答案:

答案 0 :(得分:0)

只有在加载广告后,才应启用您的按钮。在显示它之前,您必须等待它加载,并且需要花费几秒钟。 在initState上,您应该为按钮分配一个状态,这样它将被禁用。 并且在加载广告后,您应该设置setState来启用它。

if (event == RewardedVideoAdEvent.loaded) {
    ...
}