在 React Native 中多次显示 AdMob 激励广告

Show AdMob Rewarded Ad multiple times in React Native

我创建了一个按钮,只要有人点击它就会显示奖励广告。 现在有两个问题: 1. 加载广告花费的时间太长(我可以点击按钮一次或两次,然后才会发生任何事情)。 2. 我想在关闭后立即重新加载广告。可以使用,但应用需要重启。

AdMobRewardedComponent.js

  async componentDidMount() {
  await setTestDeviceIDAsync("EMULATOR");
  AdMobRewarded.setAdUnitID("ca-app-pub-3940256099942544/5224354917");

  AdMobRewarded.addEventListener("rewardedVideoDidLoad", () => {
  console.log("VideoLoaded")
  });
  AdMobRewarded.addEventListener("rewardedVideoDidFailToLoad", () =>
  console.log("FailedToLoad")
  );
  AdMobRewarded.addEventListener("rewardedVideoDidOpen", () =>
  console.log("Opened")
  );
  AdMobRewarded.addEventListener("rewardedVideoDidClose", () => {
    loadAd(request.build());
  console.log("Closed")
  });
  AdMobRewarded.addEventListener("rewardedVideoWillLeaveApplication", () =>
  console.log("LeaveApp")
  );
  AdMobRewarded.addEventListener("rewardedVideoDidStart", () =>
  console.log("Started")
  );
  AdMobRewarded.addEventListener("rewardedVideoDidRewardUser", () =>
  console.log("Rewarded"),
  );
  await AdMobRewarded.requestAdAsync();
}

componentWillUnmount() {
  AdMobRewarded.removeAllListeners();
}

_handlePress = async () => {
  await AdMobRewarded.showAdAsync();
};

render() {
  const { loadedAd } = this.state;
  return (
  <TouchableButton onPress={this._handlePress} title="Coins erhalten!" image="adButton" status="active" style={styles.adButton}/>
    );
  }
};

有没有办法在不重启整个应用程序的情况下请求新的广告? 感谢您的每一个回答!

为了防止多次按下按钮的问题,您可以使用去抖动功能:

或者,您可以在您的商店管理打开的广告,这样您就可以确保不会打开一个广告两次,并且可以在上一个广告关闭后打开一个新广告,例如:

const {  isInterstitialAdOpen,  } = useSelector(state => state.home);

if ((!__DEV__ && !isInterstitialAdOpen)) {
                dispatch(openInterstitialAd());
                AdMobInterstitial.setAdUnitID(AdMobController.getGeneralInterstitialId());
                AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
                AdMobInterstitial.addEventListener('adClosed', () => dispatch(closeInterstitialAd()));
                AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd()).catch((error) => {
                });
            }