SDKBOX Admob integration?

SDKBOX Admob integration?
0.0 0

#1

I’ve imported admob into my project, and I’ve followed the instructions for integration as best as I understand them, but they’re a bit confusing, and no ad is showing up.

Instructions are found here:
http://docs.sdkbox.com/en/plugins/admob/v3-cpp/

Some things they mention- like disabling bitcode support and whitelisting canOpenUrl- I wasn’t sure if these were necessary. They also weren’t explained, so I skipped them.

In the usage section, it says initialize admob, then cache ad (where? after initializing?) and then show ad. It mentions you can’t show an ad until it’s cached, but that it takes several minutes to cache… so where do you cache? Do you cache every time before you show? Where do you show? I’ve tried different ways of making it work, but while there is output in the console related to admob, no ad shows. Is there some more complete documentation, or even better a sample project I could look at?

SDKBOX seems really useful, I just wish I knew how to use it :smile:


#2

Let us ask @nite and/or @yinjimmy to help you.


#3

I’ve found the sample project:


I think I’ll be ok from here, thanks!


#4

Here is how I do to successfully load & show Admob ads:

AppDelegate.cpp

#include "PluginAdMob/PluginAdMob.h"

    bool AppDelegate::applicationDidFinishLaunching() {
        sdkbox::PluginAdMob::init();

And HelloWorld.cpp

#include "HelloWorldScene.h"
    #include "SimpleAudioEngine.h"
    #include "PluginAdMob/PluginAdMob.h"

    USING_NS_CC;

    static std::function<void(const std::string &)> showText = nullptr;

    class IMListener : public sdkbox::AdMobListener {
    public:
        virtual void adViewDidReceiveAd(const std::string &name) {
            if (showText)
                showText(StringUtils::format("%s name=%s", __FUNCTION__, name.c_str()));
            if (name == "interstitial")
                log("interstitial loaded");
        }

        virtual void adViewDidFailToReceiveAdWithError(const std::string &name, const std::string &msg) {
            if (showText) showText(StringUtils::format("%s\nname=%s,\nmsg=%s", __FUNCTION__, name.c_str(), msg.c_str()));
        }

        virtual void adViewWillPresentScreen(const std::string &name) {
            if (showText)
                showText(StringUtils::format("%s name=%s", __FUNCTION__, name.c_str()));
        }

        virtual void adViewDidDismissScreen(const std::string &name) {
            if (showText)
                showText(StringUtils::format("%s name=%s", __FUNCTION__, name.c_str()));
        }

        virtual void adViewWillDismissScreen(const std::string &name) {
            if (showText)
                showText(StringUtils::format("%s name=%s", __FUNCTION__, name.c_str()));

            if (name == "interstitial") {
                sdkbox::PluginAdMob::cache("interstitial");
            }
        }

        virtual void adViewWillLeaveApplication(const std::string &name) {
            if (showText)
                showText(StringUtils::format("%s name=%s", __FUNCTION__, name.c_str()));
        }
    };

    Scene *HelloWorld::createScene() {
        return HelloWorld::create();
    }
    bool HelloWorld::init() {
        if (!Scene::init()) {
            return false;
        }

        sdkbox::PluginAdMob::setListener(new IMListener());

        sdkbox::PluginAdMob::cache("interstitial");

        auto visibleSize = Director::getInstance()->getVisibleSize();
        Vec2 origin = Director::getInstance()->getVisibleOrigin();
        auto sprite = Sprite::create("background.png");
        sprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
        this->addChild(sprite, 0);

        return true;
    }


    void HelloWorld::menuCloseCallback(Ref *pSender) {
        Director::getInstance()->end();

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        exit(0);
    #endif
    }

#5

I’ll give that a shot, thanks!
One thing more @hgokturk: how do you configure the application ID? I don’t see that anywhere in the sample app


#6

It’s sdkbox_config.json file, inside Resources folder of the project.


#7

I see that’s where they set the ad IDs, but the app ID I don’t see…
ad id is something like ca-xxx-xxx, app id is something like ca-xxx~xxx


#8

ID’s of the ads are set here. I don’t get clearly what app ID to set you mean.


#9

You get an app ID when you add the app on admob, you’re supposed to initialize something like this:

// Initialize Google Mobile Ads SDK
// Sample AdMob app ID: ca-app-pub-3940256099942544~1458002511
[GADMobileAds configureWithApplicationID:@“YOUR_ADMOB_APP_ID”];

Otherwise they don’t know what ads to serve or who to pay

Edit: I’m going to call this issue solved and open a separate one for the ID. Thanks for your help!


#10

yes. SDKBox AdMob plugin does not support set app id, need to call admob native api.


#11

From a similar post, it seems like setting the app id isn’t even necessary?


#12

yes. it’s not necessary.