我已遵循以下代码中的指南来显示admob。但是,它不显示并给出错误:
"Request Error:Invalid ad request parameter..."
以下代码有什么问题吗? admob有什么工作代码吗?
var adView = new SMFBannerView({
top : '90%',
left :'0%',
animated : true
} );
adView.setAdUnitID("ca-app-pub-2822097230699730/896839XXXX");
adView.setAdSizeIndex(0);
Pages.Page1.add(adView);
adView.updateRootController();
var request = GADRequest.request();
request.testDevices = [adView.simulatorId()];
adView.loadRequest(request);
var adViewDelegate = new SMFBannerViewDelegate();
adViewDelegate.onSuccess = function (e) {
alert("Ad loaded.");
};
adViewDelegate.onError = function (e) {
alert(e);
};
adView.setDelegate(adViewDelegate);
答案 0 :(得分:0)
这是我的代码:
// SMFBannerView
var adView = new SMFBannerView();
adView.setAdUnitID("ca-app-pub-yourAdID");
// SMFBannerViewDelegate
var adViewDelegate = new SMFBannerViewDelegate();
adViewDelegate.onSuccess = function (e) {
alert("Ad loaded.");
};
adViewDelegate.onError = function (e) {
alert(e);
};
adView.setDelegate(adViewDelegate);
// Button to trigger
var btn = new SMF.UI.TextButton();
btn.onPressed = function (e) {
adView.setAdSizeIndex(1);
adView.updateRootController();
var request = GADRequest.request();
request.testDevices = [adView.simulatorId()];
adView.loadRequest(request);
};
Pages.Page1.add(adView);
Pages.Page1.add(btn);
你的问题是因为你直接打电话给admob。尝试使用此代码块。这对我来说可以。 另外,请记住,在onShow of page完成后,必须调用loadRequest方法。