在 Phonegap 应用中集成 admob 广告的最简单方法是什么?



我花了四天时间试图在我的Cordova phonegap应用程序中显示广告,但没有成功。我试过很多插件,但都不起作用。有什么我想念的吗?以下是我的代码

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)

我个人使用cordova插件admob-free,因为它按预期工作,不像其他插件那样进行广告共享。这个教程非常直接。此外,没有必要对onDeviceReady使用removeEventListener,这是不必要的,而且它只会触发一次:(

最新更新