简体   繁体   English

警报消息会影响admob广告是否弹出?

[英]alert messages impacting whether or not admob ads pop up?

I'm having some confusing experiences with admob on my first app build ever. 我在有史以来的第一个应用程序构建中就对admob感到困惑。 The android app was built with phonegap and I'm trying to display an interstitial ad twice during game play. android应用程序是使用phonegap构建的,我试图在游戏过程中两次展示插页式广告。 It's a Jeopardy style game, so an ad pops up when they hit the daily double and when they reach final jeopardy. 这是一种危险的游戏,因此当他们达到每日双打和最终危险时会弹出广告。 When I first got it to work, I had a bunch of alert messages running, and those caused the ads to be blacked out, but they would pop up at least. 当我第一次使用它时,我运行了一堆警报消息,这些消息导致广告被涂黑,但至少会弹出。 When I commented the alerts out, everything worked perfectly. 当我注释掉警报时,一切正常。 I later made some changes to the app, and I may have accidentally changed some of the code I was using for the ads by mistake. 后来我对该应用程序进行了一些更改,并且可能不小心更改了我误用于广告的一些代码。 Since that change, the ad is only popping up once at the daily double mark. 由于发生了这种变化,因此广告仅在每日两次标记后弹出一次。 I put the alerts back in to see where it was getting hung up, but when I put the alerts in, it works for both double jeopardy and the final round. 我放回警报以查看挂起的位置,但是当我放入警报时,它既适用于双重危险,也适用于最后一轮。 Except the ads are blacked out as they were before. 除了广告像以前一样被涂黑。 After more testing, the alert that is affecting everything is "alert("we've got one sitting, should be shown");" 经过更多测试之后,影响一切的警报为“警报(“应该坐一会儿,应该显示”));” as part of showInterstitialAd(). 作为showInterstitialAd()的一部分。 When commented out the ad only runs during the daily double, but when it's active a blacked out ad will play during the daily double and final round. 注释掉后,该广告仅在每日双打期间投放,但启用后,涂黑的广告将在每天的双打和最后一轮播放。

var isPendingInterstitial = false;
var isAutoshowInterstitial = false;

function prepareInterstitialAd() {
//alert("preparing");
    if (!isPendingInterstitial) {
        //alert("requesting interstitial");
        admob.requestInterstitialAd({
        autoShowInterstitial: isAutoshowInterstitial
        });
    }
}

function onAdLoadedEvent(e) {
    if (e.adType === admob.AD_TYPE.INTERSTITIAL && !isAutoshowInterstitial) {
        isPendingInterstitial = true;
        //alert("ad load event");
    }
}

function onDeviceReady() {
    document.removeEventListener('deviceready', onDeviceReady, false);

    //alert("device is ready");

    admob.setOptions({
        //alert("setting options");
        publisherId:          "pub-XXXXXXXXXXXXXXXX",
        interstitialAdId:     "ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXX",
    });   

    document.addEventListener(admob.events.onAdLoaded, onAdLoadedEvent);
    prepareInterstitialAd();
}

document.addEventListener("deviceready", onDeviceReady, false);

function showInterstitialAd() {
    //alert("trying to show");
    if (isPendingInterstitial) {
        admob.showInterstitialAd(function () {
            //alert("we've got one sitting, should be shown");
            isPendingInterstitial = false;
            isAutoshowInterstitial = false;
            prepareInterstitialAd();
        });
    } 
    else {
        //alert("not ready yet, bring it in when ready");
        isAutoshowInterstitial = true;
        admob.requestInterstitialAd({
            autoShowInterstitial: isAutoshowInterstitial
        });
    }
}

The issue isn't calling showInterstitialAd(). 问题不在于调用showInterstitialAd()。 It is getting called twice, I can tell from the alerts. 我可以从警报中得知两次。 There also shouldn't be any code running that would disrupt the ad during the final round. 在最后一轮中也不应运行任何会干扰广告的代码。 At the point the ads should display, the program is waiting on user input for their wager. 在广告应显示的​​位置,程序正在等待用户输入以进行下注。 As a test, I tried calling showInterstitialAd with setInterval at one minute intervals. 作为测试,我尝试每隔一分钟用setInterval调用showInterstitialAd。 That works and it shows the ad multiple times. 可行,并且可以多次显示广告。 I'm completely stumped. 我完全迷住了。 Unfortunately I'm not sure how to get any console logs out of this. 不幸的是,我不确定如何从中获取任何控制台日志。 I test on my browser for those, but I can't with the admob code active. 我在浏览器上测试了这些功能,但是无法启用admob代码。

Why would calling showInterstitialAd work multiple times with setInterval but not the other way? 为什么通过setInterval调用showInterstitialAd可以多次工作,而不能以其他方式工作? It is a known fact that the other way is calling showInterstitialAd both times. 众所周知,另一种方式是两次都调用showInterstitialAd。

Why would the existence of an alert cause an ad to pop up, or why would it's lack of existence cause the ad to fail? 为什么警报的存在会导致广告弹出,或者为什么警报不存在会导致广告失败?

Any help would be awesome, thanks! 任何帮助都会很棒,谢谢! For good measure, here is the code to call showInterstitialAd. 出于良好的考虑,以下是调用showInterstitialAd的代码。

function runQuestion() {
    showInterstitialAd();
    $('.clickBlock').hide();
    $('.doublePageBody').hide();
    $('.questionPage').show();
    $('.answerInputs').show();
    if (finalRound) {
        document.getElementById('category').innerHTML = titleCase(finalCategory);
    }
    if (total <= 500) {

        document.getElementById('showQuestion').innerHTML = "Place your wager between $5 and $500.";
    }
    else {
        document.getElementById('showQuestion').innerHTML = "Place your wager between $5 and " + total;
    }
    document.getElementById('timer').innerHTML = '';
}

EDIT My original post had a mistake in the code that only existed here and wasn't in my app code. 编辑我的原始帖子在仅存在于此的代码中有错误,而在我的应用程序代码中则没有。 I've removed that now. 我现在已经删除了。

The problem was the prepareInterstitialAd() in this portion of the code. 问题是代码的这一部分中的prepareInterstitialAd()。

function showInterstitialAd() {
//alert("trying to show");
if (isPendingInterstitial) {
    admob.showInterstitialAd(function () {
        //alert("we've got one sitting, should be shown");
        isPendingInterstitial = false;
        isAutoshowInterstitial = false;
        prepareInterstitialAd();
    });
} 
else {
    //alert("not ready yet, bring it in when ready");
    isAutoshowInterstitial = true;
    admob.requestInterstitialAd({
        autoShowInterstitial: isAutoshowInterstitial
    });
}

The showing of the current interstitial must have impacted the preparing of the next one since they were happening at the same time for the most part. 当前插页式广告的显示肯定已经影响了下一个插页式广告的准备,因为它们在很大程度上同时发生。 Now I'm preparing the next interstitial after the user enters their wager for the double jeopardy round. 现在,我正在为用户输入针对双重危险回合的下注之后的下一个插页式广告。 I had used this link as the example for my code in the original post, which was the first google response for "admob phonegap". 我曾在原始帖子中使用此链接作为示例代码,这是Google对“ admob phonegap”的第一个回复。 On top of the issue described above, they also misspell the prepareInterstitial function in the device ready portion, but I had caught that part right away. 除了上述问题之外,它们还在设备就绪部分中拼写了prepareInterstitial函数,但我马上就抓住了这一部分。 Just a heads up for anyone else, though. 不过,对于其他任何人,请注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM