我花了四天的时间尝试在我的Cordova phonegap应用中显示admob广告,但没有运气。我尝试了很多插件,但是都没有用。我有什么想念的吗?以下是我的代码
Index.html
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8" />
<script type="text/javascript" src="index.js" />
<script type="text/javascript" src="cordova_plugins.js" />
</head>
<body>
</body>
</html>
Index.js
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
// Set AdMobAds options:
admob.setOptions({
publisherId: "ca-app-pub-3940256099942544/1033173712", // Required
interstitialAdId: "ca-app-pub-3940256099942544/1033173712", // Optional
});
// Start showing banners (atomatic when autoShowBanner is set to true)
admob.createBannerView();
// Request interstitial (will present automatically when autoShowInterstitial is set to true)
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false)
答案 0 :(得分:2)
我个人使用cordova-plugin-admob-free,因为它可以按预期工作,并且不会像其他广告一样分享广告。本教程非常简单。另外,也不需要为remove onListener使用onDeviceReady,这是不必要的,并且只会触发一次:)