2

I'm trying to control AdMob Rewarded Video Ad by C++, since I'm working on Cocos2d-x project on IOS, following this tutorial. -> https://firebase.google.com/docs/admob/cpp/rewarded-video. But same error keeps occuring when try to request ad by LoadAd(). "HTTP load failed (error code: -999)" Click this image shows the error on logcat
I tried this on basic cocos2d-x project to make sure how Rewarded Video controlled just by C++ code not using JAVA or Obj-c or Swift. I tried and succeed on Banner Ads & Interstitial Ads and they worked just fine but only Rewarded Video keeps fail. Do I have to control AdMob Rewarded Video Ad using JAVA on Android and Obj-C on IOS respectively? or is there any other way to make succeed as same as Banner ad & Interstitial ad? Please throw me some ideas how to get through this.. Belows are whole codes on my project.

AppDelegate.h

#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "cocos2d.h"
#include "Includes.h"

class  AppDelegate : private cocos2d::Application
{
public:
    AppDelegate();
    virtual ~AppDelegate();

    virtual void initGLContextAttrs();
    virtual bool applicationDidFinishLaunching();

    ...
};

#endif

AppDelegate.cpp

#include "AppDelegate.h"
#include "HelloWorldScene.h"

bool AppDelegate::applicationDidFinishLaunching() {

    ...

    // Firebase Initialize
    firebase::App* app = firebase::App::Create(firebase::AppOptions());
    // AdMob Initialize with Test App ID
    firebase::admob::Initialize(*app, "ca-app-pub-3940256099942544~1458002511");

    auto scene = HelloWorld::createScene();
    director->runWithScene(scene);

    return true;
}

Includes.h

#ifndef _Includes_h_
#define _Includes_h_

#include "firebase/app.h"
#include "firebase/admob.h"
#include "firebase/admob/types.h"
#include "firebase/future.h"

#include "firebase/admob/rewarded_video.h"

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <jni.h>
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
extern "C" {
#include <objc/objc.h>
}  // extern "C"
#endif

// Returns a variable that describes the ad parent for the app. On Android
// this will be a JObject pointing to the Activity. On iOS, it's an ID pointing
// to the root view of the view controller.
firebase::admob::AdParent getAdParent();

#endif

Includes.cpp

#include "Includes.h"

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/jni/JniHelper.h"
#endif

USING_NS_CC;

firebase::admob::AdParent getAdParent() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    // Returns the iOS RootViewController's main view (i.e. the EAGLView).
    return (id)Director::getInstance()->getOpenGLView()->getEAGLView();
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // Returns the Android Activity.
    return JniHelper::getActivity();
#else
    // A void* for any other environments.
    return 0;
#endif
}

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "ui/CocosGUI.h"

#include "Includes.h"

class HelloWorld : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();
    CREATE_FUNC(HelloWorld);
    virtual bool init();

    cocos2d::ui::Button* btn01;
    void BtnTest();

    firebase::admob::AdRequest ad_request = {};
};

#endif

HelloWorldScene.cpp

#include "HelloWorldScene.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    return HelloWorld::create();
}

bool HelloWorld::init()
{
    if ( !Scene::init() )
        return false;

    auto pos = this->getContentSize();

    btn01 = ui::Button::create("HelloWorld.png");
    btn01->addClickEventListener(CC_CALLBACK_0(HelloWorld::BtnTest, this));
    btn01->setPosition(Point(pos.width / 2, pos.height / 2));
    this->addChild(btn01);

    firebase::admob::rewarded_video::Initialize();
    // Error occurs on LoadAd(), and below is Test Unit Id on IOS.
    firebase::admob::rewarded_video::LoadAd("ca-app-pub-3940256099942544/1712485313", ad_request);

    return true;
}

void HelloWorld::BtnTest()
{
    firebase::admob::rewarded_video::Show(getAdParent());
}

I enabled some additional features on ATS following https://developers.google.com/admob/ios/app-transport-security like this -> Click this image shows the ATS settings on Build Settings But still the error "HTTP load failed (error code: -999)" is occuring.

  • have you set NSAllowsArbitraryLoads to YES? – Amod Gokhale Nov 02 '17 at 09:45
  • Does NSAllowsArbitraryLoads in Build Settings ...? I searched info.plist , but nowhere. – Hovenia Dulcis Nov 02 '17 at 09:58
  • https://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – Amod Gokhale Nov 02 '17 at 10:26
  • I'v just done it but still see the same error – Hovenia Dulcis Nov 02 '17 at 12:29
  • if (firebase::admob::rewarded_video::LoadAdLastResult().status() == firebase::kFutureStatusComplete && firebase::admob::rewarded_video::LoadAdLastResult().error() == firebase::admob::kAdMobErrorNone) { // my_ad_parent is a reference to an iOS UIView or an Android Activity. // This is the parent UIView or Activity of the rewarded video. firebase::admob::rewarded_video::Show(my_ad_parent); } – Amod Gokhale Nov 02 '17 at 13:34
  • check loadAdLastResult() before showing it to user.. refer to this link https://firebase.google.com/docs/admob/cpp/rewarded-video – Amod Gokhale Nov 02 '17 at 13:34
  • Yes, I followed right that tutorial and aware of that firebase::Future. It'll be surely needed when used in actual game logics. In the code above, I just wanted to check if the Rewarded Video is loaded well by the code LoadAd(). – Hovenia Dulcis Nov 02 '17 at 14:10
  • I am having the exact same problem. I too am using Cocos2dx and Firebase. I have tried everything imaginable, including spending over one week refactoring my code base to ensure I'm using the lastest versions of Cocos2dX, Firebase, etc.. I have gone as far as inspecting the request/response using Charles and as far as I can tell, the response looks ok? The only clue I have is a singe request I see being made to `googleads.g.doubleclick` which causes 400 error. There is no documentation explaining what this call is supposed to do, but even cURL'ing the same url returns the same 400 error. – Jarad DeLorenzo Aug 06 '18 at 22:14

0 Answers0