2

我正在尝试在我的颤振应用中展示奖励视频广告。有时它工作得很好,有时我得到这个错误“PlatformException(ad_not_loaded,奖励视频显示失败,没有加载广告,null)”

以下是我加载和展示广告的方式:

  MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    testDevices: ['6E85178A5E7B957403B497917D014D74'],
  );
  try {
      await RewardedVideoAd.instance.load(
          adUnitId:getRewardBasedVideoAdUnitId(), targetingInfo: targetingInfo);

      await RewardedVideoAd.instance.show();
    } on PlatformException catch (e) {

      Fluttertoast.showToast(
        msg: AppStrings.adFailed,
        toastLength: Toast.LENGTH_LONG,
        timeInSecForIosWeb: 5,
      );
    }

通常这种情况发生在广告成功然后下一次失败以及成功后的时间等等,也许我需要在广告成功显示后重置一些东西?

4

1 回答 1

0

这有点晚了,但我希望它可以帮助那里的人。

上述情况通常是因为load函数在实际加载广告之前返回。

这个答案是一个技巧,而不是一个解决方案。

初始化插件后;

查看下面的代码

showRewardAd() async {

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

  bool _adIsDisplayed = false;
  do {
    try {
      _adIsDisplayed = (await RewardedVideoAd.instance.show() ?? false);
    } catch (e) {}
  } while (!_adIsDisplayed);
 }
}

调用showRewardAd将强制显示广告。不要忘记添加加载程序以在广告加载时指示进度。

我们可以利用实例的show()方法在成功时返回 a的事实,否则。RewardedVideoAdFuture<true>Future<false>

使用 do while 循环将继续尝试显示广告,直到成功,而不会引发任何错误...

这可能不是想要的行为,因此您可能希望在循环期间的某个时间点抛出错误,例如在 5 到 10 次尝试之后,因此我们没有无限循环。

于 2020-11-29T22:59:00.503 回答