1

Admob released new SDK v6.2.1, and for the past few days i've been trying to implement it without success. There is something wrong with google analytics addon main.m in the SDK:

Error 1: Stray '@' in program
Error 2: 'autoreleasepool' undeclared (first use in this function)
Error 3: Expected ';' before '{' token

main.m file:

//
// main.m
// CuteAnimals
//
// Copyright 2012 Google, Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[]) {
    @autoreleasepool {
       return UIApplicationMain(argc, argv, nil,
             NSStringFromClass([AppDelegate class]));
    }
}

I have linked all the required librarys:

AudioToolbox.framework
MessageUI.framework
AVFoundation.framework
StoreKit.framework
iAd.framework
SystemConfiguration.framework
QuartzCore.framework
OpenGLES.framework
OpenAL.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
libGoogleAdMobAds.a
libGoogleAnalytics.a
libGoogleAnalytics_debug.a

I am not even Including or implementing the GAdbannerView yet. The project wont even compile with the SDK included. Whenever i remove the Add-ons folder, which includes (DoubleClick, GoogleAnalyticsiOS_2.0beta3, Mediation, Search), the project compiles.. But if i try implementing GADBannerView, (without addons folder), Mach-O linker error comes up for missing analytics addon file.

cocos2d v1.X
Xcode v4.5.2

Is there something I'm missing here?

* EDIT *
Seems I was including everything provided in the SDK download, which includes a sample project. After including only the GAD Classes, libGoogleAdMobAds.a, README.txt, and an additional library (AdSupport.framework), It compiles just fine. Hope that helps.

GameDevGuru
  • 1,095
  • 2
  • 12
  • 27

3 Answers3

0

You can use admob in cocos2d game. Here is working code.

@interface MyMainMenu : CCLayer
{
    GADBannerView *mBannerView;
}

@implementation MyMainMenu


-(void)onEnter
{
    [super onEnter];

    [self createAdmobAds];

}

-(void)createAdmobAds
{
    AppController *app =  (AppController*)[[UIApplication sharedApplication] delegate];    
    // Create a view of the standard size at the bottom of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    mBannerView.adUnitID = MY_BANNER_UNIT_ID;

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.

    mBannerView.rootViewController = app.navController;
    [app.navController.view addSubview:mBannerView];

    // Initiate a generic request to load it with an ad.
    [mBannerView loadRequest:[GADRequest request]];

    CGSize s = [[CCDirector sharedDirector] winSize];

    CGRect frame = mBannerView.frame;
    frame.origin.y = s.height;

    frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);

    mBannerView.frame = frame;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    frame = mBannerView.frame;
    frame.origin.y = s.height - frame.size.height;
    frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);

    mBannerView.frame = frame;
    [UIView commitAnimations];    

}


-(void)showBannerView
{
    if (mBannerView) 
    {
        [UIView animateWithDuration:0.5
                              delay:0.1
                            options: UIViewAnimationCurveEaseOut
                         animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];

             CGRect frame = mBannerView.frame;
             frame.origin.y = s.height - frame.size.height;
             frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);

             mBannerView.frame = frame;
         } 
                         completion:^(BOOL finished)
         {
         }];
    }

}


-(void)hideBannerView
{
    if (mBannerView) 
    {
        [UIView animateWithDuration:0.5
                              delay:0.1
                            options: UIViewAnimationCurveEaseOut
                         animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];

             CGRect frame = mBannerView.frame;
             frame.origin.y = frame.origin.y +  frame.size.height;
             frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
         } 
                         completion:^(BOOL finished)
         {
         }];
    }

}


-(void)dismissAdView
{
    if (mBannerView) 
    {
        [UIView animateWithDuration:0.5
                              delay:0.1
                            options: UIViewAnimationCurveEaseOut
                         animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];

             CGRect frame = mBannerView.frame;
             frame.origin.y = frame.origin.y + frame.size.height ;
             frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
             mBannerView.frame = frame;
         } 
                         completion:^(BOOL finished)
         {
             [mBannerView setDelegate:nil];
             [mBannerView removeFromSuperview];
             mBannerView = nil;

         }];
    }

}
Guru
  • 21,652
  • 10
  • 63
  • 102
  • Thanks, but that's not where the problem was occurring. It couldn't even compile without code implementation. Just including the SDK gave me errors. I figured it out and while provide that answer shortly.. – GameDevGuru Jan 19 '13 at 05:04
0

Seems I was including everything provided in the SDK download, which includes a sample project. After including only the GAD Classes, libGoogleAdMobAds.a, README.txt, and an additional library (AdSupport.framework), It compiles just fine. Hope that helps.

GameDevGuru
  • 1,095
  • 2
  • 12
  • 27
0

I believe @autoreleasepool is only valid under ARC. If your project isn't using ARC, you can enable it just for that file with the -fobjc-arc compiler flag. (Or, since that main.m doesn't really do anything special, stick with the one you've got.)

rickster
  • 124,678
  • 26
  • 272
  • 326