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

后端 未结 4 1547
无人及你
无人及你 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条回答
  •  梦毁少年i
    2021-02-20 11:50

    Seems like the issue was with the event completed. Check out this code.

    MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
      keywords: ['flutterio', 'beautiful apps'],
      contentUrl: 'https://flutter.io',
      childDirected: false,
      testDevices: [], // Android emulators are considered test devices
    );
    bool _loaded = false;
    
    @override
    void initState() {
      super.initState();
    
      // load ad in the beginning
      RewardedVideoAd.instance
          .load(adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo)
          .catchError((e) => print("error in loading 1st time"))
          .then((v) => setState(() => _loaded = v));
    
      // ad listener
      RewardedVideoAd.instance.listener = (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
        if (event == RewardedVideoAdEvent.closed) {
          RewardedVideoAd.instance
              .load(adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo)
              .catchError((e) => print("error in loading again"))
              .then((v) => setState(() => _loaded = v));
        }
      };
    }
    
    
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
          child: Text(
            "Loaded = ${_loaded}",
            style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          // show ad on FAB click
          onPressed: () async {
            await RewardedVideoAd.instance.show().catchError((e) => print("error in showing ad: ${e.toString()}"));
            setState(() => _loaded = false);
          },
        ),
      );
    }
    

提交回复
热议问题