2

Hello! My game is almost done. But now I want to add ads. I use ADMob. I red the instructions but I don't have a ViewController. Because I am coding in Cocos2d & using SpriteBuilder to connect everything I only have a MainScene.m and MainScene.h.

I don't know what to do. I searched everywhere but can't find anyone in my situation.

Can someone out there please help me? My game is done, it's just the ads left. Then I'm going to pay $99 for the IOS Developer.

Thanks :)

James Webster
  • 31,873
  • 11
  • 70
  • 114
Jonte
  • 23
  • 3
  • CCDirector is the view controller. PS: be sure to test your game on as many devices as possible. Since you are not a registered developer yet you can't have done that, expect some surprises and read through apple's submission guidelines/checklist before submitting. – CodeSmile Mar 07 '14 at 22:13
  • Okey thanks so much! You guys here on Stackoverflow are som welcome to new developers ;) – Jonte Mar 08 '14 at 09:34
  • But what code should i use? None of the codes I am trying to use seems to work – Jonte Mar 08 '14 at 09:47
  • checkout this http://stackoverflow.com/questions/21846346/admob-with-cocos-2d-v3/21859218#21859218 – Guru Mar 20 '14 at 13:27

1 Answers1

1

You could try something like this

// ---------------------------------------------------------------------
#pragma mark - Advertising
// ---------------------------------------------------------------------

- (void) createPublicity
{
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    bannerView_.adUnitID = YOUR_GOOGLE_ADMOB_UNIT_ID;
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;

    bannerView_.rootViewController = rootViewController;
    [rootViewController.view addSubview:bannerView_];

    GADRequest *request = [GADRequest request];
    [bannerView_ loadRequest: request];
}

- (void) cleanupPublicity
{
    if (bannerView_ != nil)
    {
        [bannerView_ removeFromSuperview];
        bannerView_ = nil;
    }
}
Tibor Udvari
  • 2,932
  • 3
  • 23
  • 39