Sivanathan
Sivanathan

Reputation: 1213

How to implement admob on view controller?

In my app, I want to implement admob and now only I have started to learn about it. So any one please guide me and is there any nice tutorial or sample?

Upvotes: 1

Views: 2218

Answers (4)

roocell
roocell

Reputation: 2449

If you choose to use the Interface Builder approach and follow their steps there is one step missing: Add an AdViewController object to your UIViewController.h/m file and use that as the referencing object in IB. Otherwise you'll get the error:

"Must implement required method -currentViewControllerForAd:(AdMobView *)adView in your delegate"

I realize this is a basic assumption, but it caught me for a minute and i've implemented AdMob 3 times in the past (using different methods, mind you).

  • Add an ad to a view using Interface Builder
  • Add AdViewController.h and AdViewController.m to your project (located in the IBSupport subdirectory).
  • Open Interface Builder.
  • Place a 320x48 UIView where you want the ad to appear.
  • Add an Object, and change its type to AdViewController.
  • Set the view outlet of the AdViewController to your UIView.
  • Set the currentViewController outlet of the AdViewController to the UIViewController owning the xib.
  • Edit AdViewController.m to make sure that your publisher ID and other options are set correctly.

Upvotes: 2

TigerCoding
TigerCoding

Reputation: 8720

Good thing to know, Mike. They also left out one step in Interface Builder. You need to select File's Owner, and drag from Ad View Controller to the new Ad View Object. I simply cannot comprehend why Admob would leave out these details, especially when many new programmers join they're community all the time. They really need help in the documentation & tutorials department.

Upvotes: 1

David McGraw
David McGraw

Reputation: 5177

It's extremely simple. Follow the guide here: http://developer.admob.com/wiki/IPhone#AdMob_iPhone_SDK

Once you have the SDK up, you simply do:

AdMobView *ad = [AdMobView requestAdWithDelegate:<your delegate>]; // start a new ad request
ad.frame = CGRectMake(0, 432, 320, 48); // set the frame, in this case at the bottom of the screen
[self.window addSubview:ad]; // attach the ad to the view hierarchy; self.window is responsible for retaining the ad

Upvotes: 3

Tom Irving
Tom Irving

Reputation: 10059

Download the Admob SDK for iPhone and look at the example projects. It's very simple.

Upvotes: 2

Related Questions