AdMob Android Caching Issues - Ads Not Loaded/Showing

Guys

in an attempt to ensure my ads were ready to be displayed I put the following code into my AppDelegate::applicationDidFinishLaunching() method:

// cache ads first thing…
/#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
CCLOG(“AppDelegate::applicationDidFinishLaunching sdkbox::PluginAdMob::cache ‘level_1_IOS’, ‘level_2_IOS’, ‘level_3_IOS’, ‘menu_IOS’”);
sdkbox::PluginAdMob::cache(“LEVEL_1_IOS”);
sdkbox::PluginAdMob::cache(“LEVEL_2_IOS”);
sdkbox::PluginAdMob::cache(“LEVEL_3_IOS”);
sdkbox::PluginAdMob::cache(“MENU_IOS”);
/#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
CCLOG(“AppDelegate::applicationDidFinishLaunching sdkbox::PluginAdMob::cache(‘LEVEL_1’, ‘LEVEL_2’, LEVEL_3’, ‘MENU’)”);
sdkbox::PluginAdMob::cache(“LEVEL_1”);
sdkbox::PluginAdMob::cache(“LEVEL_2”);
sdkbox::PluginAdMob::cache(“LEVEL_3”);
sdkbox::PluginAdMob::cache(“MENU”);
/#endif

I discovered only the LAST ad was being cached and displayed. By the way this bug is NOT evident in the iOS build only in Android.

To cache the ads sequentially I put the following code into my AdMobEventListener and ONLY cached thr MENU ad in the AppDelegate method:

void AdMobEventListener::adViewDidReceiveAd(const std::string &name) {
CCLOG(“AdMobEventListener::adViewDidReceiveAd( %s )”, name.c_str());
if(name.compare(“MENU”)==0) {
CCLOG(“AdMobEventListener::adViewDidReceiveAd sdkbox::PluginAdMob::cache(‘LEVEL_1’)”);
sdkbox::PluginAdMob::cache(“LEVEL_1”);
}
else if(name.compare(“LEVEL_1”)==0) {
CCLOG(“AdMobEventListener::adViewDidReceiveAd sdkbox::PluginAdMob::cache(‘LEVEL_2’)”);
sdkbox::PluginAdMob::cache(“LEVEL_2”);
}
else if(name.compare(“LEVEL_2”)==0) {
CCLOG(“AdMobEventListener::adViewDidReceiveAd sdkbox::PluginAdMob::cache(‘LEVEL_3’)”);
sdkbox::PluginAdMob::cache(“LEVEL_3”);
}
}

This seems to work :slight_smile:

Not related with the issue:
I don’t think you need the #if stuff to distinguish the ad unit depending on the platform.
You can use the same keys and distinguish the ad id in sdkbox_config.json.
Something like this should work:

{
    "android": {
        "AdMob": {
            "test": false, 
            "ads": {
                "LEVEL1": {
                    "type": "interstitial", 
                    "id": "<some id>"
                },
                "LEVEL2": {
                    "type": "interstitial",
                    "id": "<some id>"
                },
                "LEVEL3": {
                    "type": "interstitial",
                    "id": "<some id>"
                }
            }
        }
    }, 
    "ios": {
        "AdMob": {
            "test": false, 
            "ads": {
                "LEVEL1": {
                    "type": "interstitial",
                    "id": "<some id>"
                },
                "LEVEL2": {
                    "type": "interstitial",
                    "id": "<some id>"
                },
                "LEVEL3": {
                    "type": "interstitial",
                    "id": "<some id>"
                }
            }
        }
    }
}