我要做的就是用户单击按钮打开广告,当用户关闭广告时他通过执行功能openVideo()自动打开视频。
库:
按钮:
<Button onPress={() => this.openAd()}> Play Video <Button>
代码:
_loadInitialState = async () => { AdMobInterstitial.setAdUnitID(INTERSTITIAL_ID); AdMobInterstitial.setTestDeviceID(TESTDEVICE_ID); await AdMobInterstitial.requestAdAsync(); await AdMobInterstitial.showAdAsync(); } openVideo(){ this.video.open(); } openAd(){ this._loadInitialState().done(); }
答案 0 :(得分:0)
在文档中,它说这是一个名为onAdViewDidDismissScreen()
的事件。我不知道您是如何实现代码的,但是我认为您正在使用expo,对吗?然后,您可以分享给我零食项目的链接吗,我可以尝试为您提供帮助。
EDIT1
Expo Admob库从react native支持imperativ API。对于侦听事件,应在componentDidMount方法中创建侦听器,然后在componentWillUnmount方法中销毁它们。
componentDidMount(){
AdMobInterstitial.addEventListener("event_name", this._functionToCall)
}
componentWillUnmount(){
AdMobInterstitial.removeAllListeners();
}
您可以阅读文档,以确保要支持或收听哪些事件。请注意,iOS和Android的每个事件都有不同的名称,因此请记住这一点。我只是根据您的示例创建了一个Expo Snack。