flutter - Rewarded Video Ads Error when Reload : “ad_not_loaded, show failed for rewarded video, no ad was loaded, null)”

后端 未结 4 1549
无人及你
无人及你 2021-02-20 10:56

i try to reload Rewarded Video Ads, when i call RewardedVideoAd.instance.load(adUnitId: \"xxx\", targetingInfo: xyz); i find below error :

4条回答
  •  孤城傲影
    2021-02-20 11:39

    Hi I think the best solution is using try catch and if there is a problem we can try to show it again. Here is my code;

    MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
      keywords: ['flutterio', 'beautiful apps'],
      contentUrl: 'https://flutter.io',
      childDirected: false,
      testDevices: [],
    );
    
    String adUnit = "ca-app-pub-6288831324909345/9733176442";
    bool tryAgain = false;
    
    await RewardedVideoAd.instance
        .load(adUnitId: adUnit, targetingInfo: targetingInfo);
    
    try {
      await RewardedVideoAd.instance.show();
    } on PlatformException catch (e) {
      tryAgain = true;
      print(e.message);
    }
    
    RewardedVideoAd.instance.listener =
        (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
      switch (event) {
        case RewardedVideoAdEvent.rewarded:
          setState(() {
            // Here, apps should update state to reflect the reward.
            print("_goldCoins += rewardAmount");
          });
          break;
    
        case RewardedVideoAdEvent.loaded:
          if (tryAgain) RewardedVideoAd.instance.show();
          break;
    
        default:
          print(event.toString());
          break;
      }
    };
    

提交回复
热议问题