2

我正在尝试通过 C++ 控制 AdMob Rewarded Video Ad,因为我正在按照本教程在 IOS 上处理 Cocos2d-x 项目。-> https://firebase.google.com/docs/admob/cpp/rewarded-video。但是当尝试通过 LoadAd() 请求广告时,同样的错误不断发生。“HTTP 加载失败(错误代码:-999)”单击此图像显示 logcat 上的错误
我在基本的 cocos2d-x 项目上尝试了这个,以确保奖励视频如何仅由 C++ 代码控制,而不是使用 JAVA 或 Obj-c 或 Swift。我在横幅广告和插页式广告上尝试并取得了成功,它们工作得很好,但只有奖励视频一直失败。我是否必须分别在 Android 上使用 JAVA 和在 IOS 上使用 Obj-C 来控制 AdMob Rewarded Video Ad?或者有没有其他方法可以像横幅广告和插页式广告一样成功?请给我一些想法如何解决这个问题。以下是我项目的完整代码。

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

包括.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

包括.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这样 的 https://developers.google.com/admob/ios/app-transport-security之后在 ATS 上启用了一些附加功能->单击此图像显示构建设置上的 ATS 设置 但仍然出现错误“HTTP 加载失败(错误代码:-999)”正在发生。

4

0 回答 0