[Solved] Problem Interstitial admob on Cocos Creator

Hello guys i have a problem, i use cocos creator 1.5 and when i monsters the Interstitial admob (Advertising in full screen) and i click it take me on apple store but when i return to the game this is blocked, How can I fix it?

Code:

Button call:

sdkbox.PluginAdMob.show(‘gameover’);

AdMob.js

admobInit: function() {
    if(cc.sys.isMobile) {
        var self = this;
        sdkbox.PluginAdMob.setListener({
            adViewDidReceiveAd: function(name) {
                //cc.log('adViewDidReceiveAd name=' + name);
            },
            adViewDidFailToReceiveAdWithError: function(name, msg) {
                //cc.log('adViewDidFailToReceiveAdWithError name=' + name + ' msg=' + msg);
            },
            adViewWillPresentScreen: function(name) {
                //cc.log('adViewWillPresentScreen name=' + name);
            },
            adViewDidDismissScreen: function(name) {
                //cc.log('adViewDidDismissScreen name=' + name);
            },
            adViewWillDismissScreen: function(name) {
                //cc.log('adViewWillDismissScreen=' + name);
            },
            adViewWillLeaveApplication: function(name) {
                //cc.log('adViewWillLeaveApplication=' + name);
            }
        });
        sdkbox.PluginAdMob.init();
    }
},

Update 1:
I have add code in AdMob.js

cc.game.on(cc.game.EVENT_HIDE, function (event) {
    console.log("AdMob=================================>HIDE TRUE");

});

cc.game.on(cc.game.EVENT_SHOW, function (event) {
    console.log("AdMob=================================>SHOW TRUE");
});

Consol Log xcode:
D/AudioEngine-inl.mm (147): UIApplicationWillResignActiveNotification
AdMob=================================>HIDE TRUE
2017-06-16 08:27:30.084016+0200 Game-mobile[13307:3297968] dnssd_clientstub write_all(37) DEFUNCT
2017-06-16 08:27:30.084154+0200 Game-mobile[13307:3297968] dnssd_clientstub deliver_request ERROR: write_all(37, 70 bytes) failed
2017-06-16 08:27:30.084394+0200 Game-mobile[13307:3297968] dnssd_clientstub write_all(37) DEFUNCT
D/AudioEngine-inl.mm (157): UIApplicationDidBecomeActiveNotification

Game is blocked and the console.log(“AdMob=================================>SHOW TRUE”); It does not appear

Update 2:
The game blocked even if you start the Interstitial admob (Advertising in full screen) and while we look at the announcement we go in the background, when we return in the game it will be blocked. To unlock it, we’ll just go back to the background and return to the game. Why is this happening? Is this an issue with AdMob?

Update 3:
Removing in the file AppController.mm in the applicationDidEnterBackground the line
cocos2d::Application::getInstance()->applicationDidEnterBackground();
Everything works perfectly.

what is the stuck ? Could you share some pictures or some output log here ?

Sorry, i was wrong, i return to the game this is blocked

Update 1:
I have add code in AdMob.js

    cc.game.on(cc.game.EVENT_HIDE, function (event) {
        console.log("AdMob=================================>HIDE TRUE");
   });

    cc.game.on(cc.game.EVENT_SHOW, function (event) {
        console.log("AdMob=================================>SHOW TRUE");
    });

Consol Log xcode:
D/AudioEngine-inl.mm (147): UIApplicationWillResignActiveNotification
AdMob=================================>HIDE TRUE
2017-06-16 08:27:30.084016+0200 Game-mobile[13307:3297968] dnssd_clientstub write_all(37) DEFUNCT
2017-06-16 08:27:30.084154+0200 Game-mobile[13307:3297968] dnssd_clientstub deliver_request ERROR: write_all(37, 70 bytes) failed
2017-06-16 08:27:30.084394+0200 Game-mobile[13307:3297968] dnssd_clientstub write_all(37) DEFUNCT
D/AudioEngine-inl.mm (157): UIApplicationDidBecomeActiveNotification

Game is blocked and the console.log(“AdMob=================================>SHOW TRUE”); It does not appear

Update 2:
The game blocked even if you start the Interstitial admob (Advertising in full screen) and while we look at the announcement we go in the background, when we return in the game it will be blocked. To unlock it, we’ll just go back to the background and return to the game. Why is this happening? Is this an issue with AdMob?

My Dear,

you can check our sample, it works. But I’ll check the cocos creator project.

tested with:

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
    },
    
    showText: function(str) {
        console.log(str);
    },

    // use this for initialization
    onLoad: function () {
        var self = this;
        var plugin = sdkbox.PluginAdMob;
        plugin.setListener({
            adViewDidReceiveAd: function(name) {
                self.showText('adViewDidReceiveAd name='+name);
                if (name == self.kHomeBanner) {
                    plugin.show(name);
                }
            },
            adViewDidFailToReceiveAdWithError: function(name, msg) {
                self.showText('adViewDidFailToReceiveAdWithError name='+name+' msg='+msg);
            },
            adViewWillPresentScreen: function(name) {
                self.showText('adViewWillPresentScreen name='+name);
            },
            adViewDidDismissScreen: function(name) {
                self.showText('adViewDidDismissScreen name='+name);
                plugin.cache(name);
            },
            adViewWillDismissScreen: function(name) {
                self.showText('adViewWillDismissScreen='+name);
            },
            adViewWillLeaveApplication: function(name) {
                self.showText('adViewWillLeaveApplication='+name);
            },
            reward: function(name, currency, amount) {
                self.totalAmount = self.totalAmount + amount;
                self.showText('reward='+name+' '+currency+' '+amount);
                self.showText('totalAmount='+self.totalAmount);
            }
        });
        plugin.init();
    
        this.node.on('click', function(event) {
            console.log('Hello!');  
            sdkbox.PluginAdMob.show("gameover");
        })
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});

add this component to button.

no game blocked, did you change AppController.mm or AppDelegate.cpp ?

Update 3:
Removing in the file AppController.mm in the applicationDidEnterBackground the line cocos2d::Application::getInstance()->applicationDidEnterBackground(); Everything works perfectly.

1 Like

Can this cause some problems? Can I put solved of this discussion?

Now sure why this fixed your issue, but if it works than it’s good

Hey everyone, I ran into this problem as well and I would like to thank Jin_90 for pointing this issue out. While commenting out AppController.mm applicationDidEnterBackground works, it’s not an elegant solution. If you look into the Cocos class appDelegate.cpp, you will see that Cocos calls director director->stopAnimation(); and director->startAnimation(); respectively. Problem is iOS sends the app to background when you click the interstitial but it doesn’t bring the app to foreground when you dismiss the interstitial. Rather than commenting out code, you can call cc.director.startAnimation(); because if you remove applicationDidEnterBackground you will no longer get calls on cc.game.EVENT_HIDE event…

Here is my code… I made a file for globals, my global is:

var gamePaused = false;

Then:

cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function () { //console.log('paused'); gamePaused = true; }); cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () { //console.log('resumed'); gamePaused = false; });

In my touch listener I do…

if(gamePaused){ //console.log('resumed...'); cc.director.startAnimation(); gamePaused = false; }

Last line of code is important because if your app doesn’t go completely to background, cc.game.EVENT_SHOW is not called…

I thank the Cocos team for their work and the SDKBox team as well. I just wish they both had better documentation…

1 Like

So with this approach, do you still need to comment out applicationDidEnterBackground?

No, commenting it out will stop cc.game.EVENT_HIDE from working. Which will mess things up if you want to stop audio or other process when the application enters the background.