我最近一直在制作一个真正的应用程序。我还使用谷歌的admob放置了一个广告横幅,直到几天前才出现任何广告。 设置下面的广告道具会导致错误。
<AdMobBanner
bannerSize="banner"
adUnitID="ca-app-pub-@@@@@@@"
testDeviceID="EMULATOR"
servePersonalizedAds = {true}
onDidFailToReceiveAdWithError={this.bannerError}
/>
错误如下。
The `testDeviceID` prop of AdMobBanner is deprecated. Test device IDs are now set globally. Use AdMob.setTestDeviceIDAsync instead.
如果您能帮助我,我将不胜感激。
我遇到了同样的问题,他们应该更新世博会网站上的信息。我相信这也应该适用于横幅。
进口:
import {
setTestDeviceIDAsync, //<--- I forgot this first time
AdMobInterstitial
}from 'expo-ads-admob';
挂载后初始化:
componentDidMount(){
this.initAds().catch((error) => console.log(error));
}
initAds = async () => {
AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712') //test id
await setTestDeviceIDAsync('EMULATOR');
}
从按钮或任何您喜欢的内容触发此功能:
_openInterstitial = async () => {
try {
this.setState({ disableInterstitialBtn: true })
await AdMobInterstitial.requestAdAsync()
await AdMobInterstitial.showAdAsync()
} catch (error) {
console.error(error)
} finally {
this.setState({ disableInterstitialBtn: false })
}
}