How to integrate GoogleAdmob in cocos2d-x (Portrait mode) | Techbirds

In order to integrate the google admob to your existing project,firstly copy the following banner view classes and GoogleAdMobAdsSDK in proj.ios folder of your project

Banner View Classes
GoogleAdMobAdsSDK

After copying,the folder will look like this:

screen-shot-2014-06-25-at-10-49-42-am-300x99-4347875

Now your project folder is ready for the integration,go to your Xcode project,open it,add these classes of banner view to your project directly by right click on project and click on “Add Files to project_name” option

For GoogleAdMobAdsSDK,add this in Frameworks folder and also make sure the following frameworks should be in your project,if not,then must add through Link Binary With Libraries option in Build Phases:

screen-shot-2014-06-25-at-11-59-51-am2-209x300-6087904

After making all above changes,the project in Xcode look like this:

screen-shot-2014-06-25-at-11-51-52-am-133x300-8233599

Now make changes in AppController.h(inside the ios folder) class so that it will look like this:

screen-shot-2014-06-25-at-11-06-46-am2-300x115-2550777

Go to AppController.mm,and add the following lines after “@implementation AppController”

@synthesize window; @synthesize viewController; @synthesize bvc;

@synthesize window;

@synthesize viewController;

@synthesize bvc;

and it will shown as:

screen-shot-2014-06-25-at-11-07-06-am-300x168-1936019

Now go to function – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions inside the same class and search for the following lines:

// Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn’t work on iOS6 [window addSubview: viewController.view]; } else { // use this method on ios6 [window setRootViewController:viewController]; }

  // Set RootViewController to window

    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)

    {

        // warning: addSubView doesn’t work on iOS6

        [window addSubview: viewController.view];

    }

    else

    {

        // use this method on ios6

        [window setRootViewController:viewController];

    }

Delete these above lines and add the following bvc banner view code after the line “viewController.view = __glView;”

bvc=[[BannerViewController alloc]initWithContentViewController:viewController]; // Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn’t work on iOS6 [window addSubview: bvc.view]; } else { // use this method on ios6 [window setRootViewController:bvc]; }

bvc=[[BannerViewController alloc]initWithContentViewController:viewController];

    // Set RootViewController to window

    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)

    {

        // warning: addSubView doesn’t work on iOS6

        [window addSubview: bvc.view];

    }

    else

    {

        // use this method on ios6

        [window setRootViewController:bvc];

    }

and it will look like this:

screen-shot-2014-06-25-at-11-07-57-am-300x169-7308627

Now,2 more imp. things left,firstly make following changes in BannerViewController.m file:

_gAdBannerView.adUnitID = @”YOUR_AD_UNIT_ID”//your admob id

_gAdBannerView.adUnitID = @”YOUR_AD_UNIT_ID”//your admob id

Next go to function named as -(void)loadReqForAdmob:(BannerViewController*)ctrll inside the same class and change the UDID numbers as per your devices:

NSString *iPadMini = @”YOUR_UDID_NUMBER”; NSString *iPhone5 = @”YOUR_UDID_NUMBER”; NSString *iphone4 = @”YOUR_UDID_NUMBER”; NSString *ipad = @”YOUR_UDID_NUMBER”; NSString *iPod = @”YOUR_UDID_NUMBER”; NSString *iPhone = @”YOUR_UDID_NUMBER”;

NSString *iPadMini = @”YOUR_UDID_NUMBER”;

NSString *iPhone5 = @”YOUR_UDID_NUMBER”;

NSString *iphone4 = @”YOUR_UDID_NUMBER”;

NSString *ipad = @”YOUR_UDID_NUMBER”;

NSString *iPod = @”YOUR_UDID_NUMBER”;

NSString *iPhone = @”YOUR_UDID_NUMBER”;

Now run your project,if it shows some error of weak property of BannerViewController.m,then add “-fobjc-arc” in front of BannerViewController.m in Compile Sources inside the Build Phases of project TARGETS:shown as below

screen-shot-2014-06-25-at-12-16-13-pm-300x153-8211322

1,621 total views, 2 views today

Share this Onfacebook-2200151twitter-1755597linkedin-1590108google-1290533