如何使用react-native-admob显示admob非页内广告?

时间:2018-09-17 14:08:33

标签: react-native react-native-android

我正在尝试显示admob非页内广告,但出现此错误。 admob横幅广告效果很好,唯一的问题是插页式广告。

这是我的代码:

import {AdMobInterstitial} from 'react-native-admob';
    componentDidMount() {
    AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
    AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
    }

Screenshot

1 个答案:

答案 0 :(得分:0)

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() {
        .......
    }
}