[SOLVED]How to integrate fullscreen admob ads in ios cocos2dx 3.3

Hi,

Please help me how to integrate fullscreen admob ads in ios.

I’m not good at in objective c language.

I’m using Xcode 6.3 and cocos2dx 3.3 version.

I have successfully integrated banner ads.

Thanks.

Refer this link for steps to add full screen ads https://developers.google.com/mobile-ads-sdk/docs/admob/ios/interstitial.

Hi,

Thanks for your reply.

According to the guide on https://developers.google.com/mobile-ads-sdk/docs/admob/ios/interstitial

First of all I created a file ViewController.h

which is as follows:-

#ifndef HelloWorld_ViewController_h
#define HelloWorld_ViewController_h

#import <UIKit/UIKit.h>

#import <UIKit/UIKit.h>

////extern NSString * const BannerViewActionWillBegin;
extern NSString * const BannerViewActionDidFinish;

@interface ViewController : UIViewController

  • (void)viewDidLoad;
    @end
    #endif

After that I created ViewController.m file which is as follows:-

#import <Foundation/Foundation.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <UIKit/UIKit.h>

//@import GoogleMobileAds;

#import “ViewController.h”

@interface ViewController ()

@property(nonatomic, strong) GADInterstitial *interstitial;

@end

@implementation ViewController{}

  • (void)viewDidLoad {
    [super viewDidLoad];
    self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@“ca-app-pub-3940256099942544/4411468910”];

    GADRequest *request = [GADRequest request];
    request.testDevices = @[ kGADSimulatorID ];

    [self.interstitial loadRequest:request];
    if ([self.interstitial isReady]) {
    [self.interstitial presentFromRootViewController:self];
    }
    }
    @end

Now how to call viewDidLoad() function from my game.cpp file.

I learnt a tutorial “onHow to call objective C from c++ in cocos2d-x” on http://techbirds.in/how-to-call-objective-c-from-c-in-cocos2d-x/.

According to this tutorial I created ObjCCalls.h file which is as follows:-

#ifndef HelloWorld__ObjCCalls
#define HelloWorld__ObjCCalls

#include <stdio.h>
class ObjCCalls{
public:
static void objectiveC_call();
};
#endif /* defined(HelloWorld__ObjCCalls) */

And after that I created ObjCCalls.mm file which is as follows:-

#import <Foundation/Foundation.h>
//#import “GADInterstitial.h”
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <UIKit/UIKit.h>

//@import GoogleMobileAds;

#include “ObjCCalls.h”
void ObjCCalls::objectiveC_call()
{
//your objective c code here
NSLog(@“Hello World”);
CCLOG(“Hello World”);

}

After that I call the function objectiveC_call() of ObjCCalls.mm class in my GameScene.cpp as follows-

void GameScreen::obCCalling()
{
//calling objective c code
ObjCCalls::objectiveC_call();
}

After that when I run the code It successfully call the objective c function from my gameScene.cpp class and prints the “Hello World” in log file.

Now the problem is that I don’t know Objective c language.

In tutorial of “onHow to call objective C from c++ in cocos2d-x” they are using class.

And in tutorial of admob interstitial they are using interface.

Now Please tell me how can I call the function viewDidLoad() from my GameScene.cpp file.

Thanks.

You can initialise interstitial in default AppController file,no need to create separate viewcontroller file.

Add ObjectiveCCalls file as follows.

ObjectiveCCalls.h
include “cocos2d.h”
class ObjectiveCCalls
{
public:

static void loadIntertialAd();

};

ObjectiveCCalls.mm
#include “ObjectiveCCalls.h”
#include “ObjectiveC.h”
void ObjectiveCCalls:: loadIntertialAd()
{
[ObjectiveC loadIntertialAd];
}

Add ObjectiveC file as follows.

ObjectiveC.h

#import “cocos2d.h”
#import “AppController.h”

using namespace cocos2d;

@interface ObjectiveC : NSObject
{

}

+(void)loadIntertialAd;
@end

ObjectiveC.mm
@implementation ObjectiveC
+(void)loadIntertialAd
{
AppController *controller = (AppController *) [UIApplication sharedApplication].delegate;
[controller loadInterstitial];
}
Add loadInterstitial method in AppController file.

Thank you very much for replying I’m trying your solution.

And I will tell you about the result of using it.

Thanks.

Hi, manjureddy48

I code as you tell me.

Can you please tell me how to Add loadInterstitial method in AppController file.

And what code should I write in that method ?

When I try to add it I’m getting errors.

Thanks

Add this code to loadInterstitial method to load intersitial ads.
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@“ca-app-pub-3940256099942544/4411468910”];

GADRequest *request = [GADRequest request];
// Requests test ads on test devices.
request.testDevices = @[@“2077ef9a63d2b398840261c8221a0c9b”];
[self.interstitial loadRequest:request];

To show interstitial ads add this code in separate method.
[self.interstitial presentFromRootViewController:self.viewController];

hi,
Thanks for reply.

I added - (void)loadIntertialAd; in AppController.h file.

After that when I add loadIntertialAd method in AppController.mm as follows

  • (void)loadIntertialAd() {

}

I’m getting error “Expected method body”.

How to solve it ?

Thanks.

Refer this link for basics of objective C methods. http://blog.teamtreehouse.com/the-beginners-guide-to-objective-c-methods

Ok, thanks for all your support.

Now I’m going to home from office. I’ll see it tomorrow.

Thanks.

Hi, manjureddy48

Can you tell me how to write loadIntertialAd method in AppController.mm

I don’t have enough time to learn Objective c language.

My boss said finish it quickly.

Please help me.

Hi,

Any one in community can help me in showing fullscreen ad using admob.

If someone implemented in there game please share code with the community.

Hi thanks for all your support I integrated admob ads using the following tutorial

It is very nice and simple to use.

Thanks.

1 Like