【问题标题】:Show AdMob Rewarded Ad multiple times in React Native在 React Native 中多次显示 AdMob 奖励广告
【发布时间】:2020-04-22 14:33:53
【问题描述】:

我创建了一个按钮,用于在点击时显示奖励广告。 现在有两个问题: 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}/>
    );
  }
};

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

【问题讨论】:

    标签: android react-native admob admob-rewardedvideoad


    【解决方案1】:

    为了防止按钮可以多次按下的问题,您可以使用 debounce 功能: React Native: Using lodash debounce

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

    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) => {
                    });
                }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多