[IOS] Add Admobs into ios app


Heres a quick guide to get Admob ads working in your monkey app.
This guide will display the ads at the bottom of a portrait screen.
This guide is based on the iOS guide from google here
http://code.google.com/mobile/ads/docs/ios
First, set up an iOS ad in Admob..
Second, open up your latest compiled project in xcode and add your project
Thirdly, add the extra libs to your project in xcode

AdSupport.framework
AudioToolbox.framework
MessageUI.framework
SystemConfiguration.framework
StoreKit.framework

Now, its time to alter the main.h and main.mm files.
Open up main.h and add the create ad banner code to the main view
// ***** MonkeyViewController *****

@interface MonkeyViewController : UIViewController{
  GADBannerView *bannerView_;
@public
}
Next open up main.mm and add the import line for the ad lib
#import "GADBannerView.h"
next add the following to the top of @implementation MonkeyViewController
- (void)viewDidLoad {
  [super viewDidLoad];

  // Create a view of the standard size at the bottom of the screen.
  bannerView_ = [[GADBannerView alloc]
                   initWithFrame:CGRectMake(0.0,
  [[UIScreen mainScreen] bounds].size.height - GAD_SIZE_320x50.height,
                                            GAD_SIZE_320x50.width,
                                            GAD_SIZE_320x50.height)];

  // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
  bannerView_.adUnitID = @"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.
  bannerView_.rootViewController = self;
  [self.view addSubview:bannerView_];

  // test devivce
 GADRequest *request = [GADRequest request];
 
 request.testDevices = [NSArray arrayWithObjects:
   GAD_SIMULATOR_ID,                               // Simulator
   nil];  
 
 // Initiate a generic request to load it with an ad.
  [bannerView_ loadRequest:request];
 
 
}

- (void)viewDidUnload {
  [bannerView_ release];
}

- (void)dealloc {
  [super dealloc];
}
replacing UNIT_ID with your advert unit ID
That should be it.. recompile and a test advert should appear in the simulator.
I don't know what happens if you upload to itunes and download to a real device. you may have to remove the following code
request.testDevices = [NSArray arrayWithObjects:
         GAD_SIMULATOR_ID,                               // Simulator
         nil];


source from: http://www.monkey-x.com/Community/posts.php?topic=1246&page=1

留言

這個網誌中的熱門文章

How to PHP export to Excel 2

html viewport meta