首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用react-native-admob显示admob Interstitial?

如何使用react-native-admob显示admob Interstitial?
EN

Stack Overflow用户
提问于 2018-09-17 22:08:33
回答 1查看 2.1K关注 0票数 1

我正在尝试显示admob Interstitial,但出现此错误。admob横幅工作正常,唯一的问题是Interstitial。

这是我的代码:

代码语言:javascript
复制
import {AdMobInterstitial} from 'react-native-admob';
    componentDidMount() {
    AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
    AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
    }

Screenshot

EN

回答 1

Stack Overflow用户

发布于 2019-02-07 14:47:59

代码语言:javascript
复制
import {AdMobBanner,AdMobInterstitial,PublisherBanner,AdMobRewarded} from 'react-native-admob';
class Alpha extends React.Component {
    componentWillMount(){
        this.makeAdmobRequest();
        setTimeout(()=>{
            this.makeRemoteRequest()
        },1000);
        setTimeout(()=>{
            this.showInterstitial()
        },60000);
    }  
    makeAdmobRequest=()=>{
        return  fetch('http://url/admob_setting.php?cat_id=2')
        .then((response) => response.json())
        .then((responseJson) =>
        {
            var bannerid1=responseJson[0]['banner_add'];
            this.setState({
                bannerid1:responseJson[0]['banner_add'],
                interestitialid:responseJson[0]['interestial_add'],
            });
        })
        .catch((error) =>
        {
            console.error(error);
        });
    }

    renderAdd(){
        if(this.state.bannerid1){
            return(
                <View style={{flex:1}}>
                    <AdMobBanner
                    adSize="banner"
                    adUnitID={this.state.bannerid1}
                    testDeviceID="EMULATOR"
                    didFailToReceiveAdWithError={this.bannerError} />
                </View>
            );
        }
    }

    showInterstitial() {
        AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
        AdMobInterstitial.setAdUnitID(this.state.interestitialid);
        AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
    }
    render() {
        .......
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52369682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档