googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
335 stars 274 forks source link

RewardedAd' onAdFailedToShowFullScreenContent: AdError(code: 17, domain: com.google.admob, message: The provided view controller is not being presented.) #1134

Closed webby-genius closed 1 month ago

webby-genius commented 1 month ago

1st time ads show perfectly but 2nd time get error (RewardedAd' onAdFailedToShowFullScreenContent: AdError(code: 17, domain: com.google.admob, message: The provided view controller is not being presented.)) then 3rd time ads show perfectly and it's sequent continue.. it's issue generate in iOS device only. android device wok perfectly

google_mobile_ads: ^5.1.0 3.19.6 -> Flutter SDK 3.3.4 -> (Flutter)Dart SDK

this is my code

static RewardedAd? rewardedAd; static int numRewardedLoadAttempts = 0; static int maxFailedLoadAttempts = 3; static int life = 0;

void createRewardedAd() { RewardedAd.load( adUnitId: AdHelper.rewardedAdUnitId, request: AdRequest(), rewardedAdLoadCallback: RewardedAdLoadCallback( onAdLoaded: (RewardedAd ad) { debugPrint('$ad loaded....Done'); rewardedAd = ad; numRewardedLoadAttempts = 0; }, onAdFailedToLoad: (LoadAdError error) { debugPrint('RewardedAd failed to load: $error'); rewardedAd = null; numRewardedLoadAttempts += 1; if (numRewardedLoadAttempts < maxFailedLoadAttempts) { createRewardedAd(); } }, ), ); }

void showRewardedOneTimeAd({void Function(RewardedAd)? onAdDismissedFullScreenContent}) { if (rewardedAd == null) { debugPrint('Warning: attempt to show rewarded before loaded.'); // Optionally, show a message to the user that the ad is not ready yet. return; }

rewardedAd!.fullScreenContentCallback = FullScreenContentCallback(
  onAdShowedFullScreenContent: (RewardedAd ad) {
    debugPrint('ad onAdShowedFullScreenContent.');
    Future.delayed(
      const Duration(seconds: 3),
      () {
        debugPrint("---------- AD CREATE SUCCESS ------------");
        createRewardedAd();
      },
    );
  },
  onAdDismissedFullScreenContent: onAdDismissedFullScreenContent ??
      (RewardedAd ad) {
        debugPrint('$ad onAdDismissedFullScreenContent.');
        ad.dispose();
        // Optionally, load a new ad after the current one is dismissed.
        debugPrint("isShowAgain 000000--->>>>> $isShowAgain");
      },
  onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) {
    debugPrint('$ad onAdFailedToShowFullScreenContent: $error');
    ad.dispose();
    createRewardedAd();
  },
);

rewardedAd!.setImmersiveMode(true);
rewardedAd!.show(onUserEarnedReward: (AdWithoutView ad, RewardItem reward) {
  life += 1;
  debugPrint('User earned reward: ${reward.amount} ${reward.type}');
});
rewardedAd = null;

}

malandr2 commented 1 month ago

Hi @webby-genius, this code snippet looks fine in regards to your error. "The provided view controller is not being presented" error happens when the provided view controller view's window is nil. Can you please share a minimal, reproducible example of your issue so we can take a closer look? Thanks

webby-genius commented 1 month ago
                         RewardedeAdsWidget().showRewardedOneTimeAd(
                          onAdDismissedFullScreenContent: (RewardedAd ad) async {
                            ad.dispose();
                            await RewardedeAdsWidget().createRewardedAd();
                                  RewardedeAdsWidget().showRewardedOneTimeAd(
                                    onAdDismissedFullScreenContent: (RewardedAd ad) async {
                                      ad.dispose();
                                      await RewardedeAdsWidget().createRewardedAd();
                                    },
                                  );
                          },
                        );

Screenshot 2024-07-17 at 9 53 36 AM

webby-genius commented 1 month ago

i need to rewarded ad show back to back 2 times and it's working fine in android device but in iOS device i found upper error when 2nd time ad show and this (2nd ad call) onAdDismissedFullScreenContent event as i show above code

malandr2 commented 1 month ago

Hi @webby-genius, the error you are experiencing is iOS-only so it is expected to work on Android. It also against policy to serve back-to-back rewarded ads. See number 2 of implementation requirements. You can only serve rewarded ads after a user has opted in to be served that particular ad. It's recommended to update your implementation and in doing so, you will avoid this error