IM上的AdMob奖励视频加载失败

时间:2017-11-02 09:15:36

标签: android ios admob cocos2d-x rewardedvideoad

我正在尝试通过C ++控制AdMob奖励视频广告,因为我正在按照本教程在IOS上开展Cocos2d-x项目。 - > https://firebase.google.com/docs/admob/cpp/rewarded-video。但是当尝试通过LoadAd()请求广告时,同样的错误仍然存​​在。 “HTTP加载失败(错误代码:-999)”Click this image shows the error on logcat
我在基本的cocos2d-x项目上尝试了这个,以确保Rewarded Video如何通过不使用JAVA或Obj-c或Swift的C ++代码来控制。我试过Banner Ads&非页内广告和他们的工作得很好,但只有Rewarded Video保持失败。我是否必须分别使用Android上的JAVA和IOS上的Obj-C来控制AdMob奖励视频广告?还是有其他方法可以像Banner ad&插页式广告?请告诉我如何解决这个问题。在我的项目中,Belows是完整的代码。

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());
}

我在https://developers.google.com/admob/ios/app-transport-security之后在ATS上启用了一些其他功能 - &gt;  Click this image shows the ATS settings on Build Settings 但仍然出现错误“HTTP加载失败(错误代码:-999)”。

0 个答案:

没有答案