开发者

How to implement admob on view controller?

开发者 https://www.devze.com 2023-01-08 11:14 出处:网络
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?It\'s extremely simple. Follow th

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?


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


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消