我正在使用此代码实施Ad Mob。但是它失败了,我得到了错误。 请为我建议一种更好的方式来实现此代码或此代码中所需的任何更改。
我在手机而不是模拟器上使用react native expo。实际上我无法理解该错误。 我已经包含了我得到的错误图像。如果您有任何想法,请帮助我。
class App extends React.Component {
componentDidMount() {
AdMobInterstitial.setTestDeviceID("Phone");
// ALWAYS USE TEST ID for Admob ads
AdMobInterstitial.setAdUnitID(ADMOBID);
AdMobInterstitial.addEventListener("interstitialDidLoad", () =>
console.log("interstitialDidLoad")
);
AdMobInterstitial.addEventListener("interstitialDidFailToLoad", () =>
console.log("interstitialDidFailToLoad")
);
AdMobInterstitial.addEventListener("interstitialDidOpen", () =>
console.log("interstitialDidOpen")
);
AdMobInterstitial.addEventListener("interstitialDidClose", () =>
console.log("interstitialDidClose")
);
AdMobInterstitial.addEventListener("interstitialWillLeaveApplication", () =>
console.log("interstitialWillLeaveApplication")
);
AdMobRewarded.setTestDeviceID("EMULATOR");
// ALWAYS USE TEST ID for Admob ads
AdMobRewarded.setAdUnitID("ca-app-pub3940256099942544/1712485313");
AdMobRewarded.addEventListener("rewardedVideoDidRewardUser", () =>
console.log("interstitialDidLoad")
);
AdMobRewarded.addEventListener("rewardedVideoDidLoad", () =>
console.log("interstitialDidLoad")
);
AdMobRewarded.addEventListener("rewardedVideoDidFailToLoad", () =>
console.log("interstitialDidLoad")
);
AdMobRewarded.addEventListener("rewardedVideoDidOpen", () =>
console.log("interstitialDidLoad")
);
AdMobRewarded.addEventListener("rewardedVideoDidClose", () =>
console.log("interstitialDidLoad")
);
AdMobRewarded.addEventListener("rewardedVideoWillLeaveApplication", () =>
console.log("interstitialDidLoad")
);
}
componentWillUnmount() {
AdMobInterstitial.removeAllListeners();
AdMobRewarded.removeAllListeners();
}
bannerError() {
console.log("An error");
return;
}
showInterstitial() {
// first - load ads and only then - show
AdMobInterstitial.requestAd(() => AdMobInterstitial.showAd());
}
showRewarded() {
// first - load ads and only then - show
AdMobRewarded.requestAd(() => AdMobRewarded.showAd());
}
render() {
return (
<View style={styles.container}>
<AdMobBanner
bannerSize="fullBanner"
adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
testDeviceID="Phone"
servePersonalizedAds // true or false
onDidFailToReceiveAdWithError={this.bannerError}
/>
// Display a DFP Publisher banner
<PublisherBanner
bannerSize="fullBanner"
adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
testDeviceID="EMULATOR"
onDidFailToReceiveAdWithError={this.bannerError}
onAdMobDispatchAppEvent={this.adMobEvent}
/>
</View>
);
}
}