Saturday, March 24, 2012

Integrating AdMob Ads in a PhoneGap Project (iOS)


  1. Open the phonegap project to which AdMob is to be added.

  2. Import GoogleAdMobAdsSDK which can be found here.

  3. Add MessageUI.framework to the project. To do this " click on project name , go to summary tab, scroll down to the framework section and click +. Then select MessageUI.framework".

  4. In AppDelegate.h import "GADBannerView.h" and add "GADBannerView *bannerView_;" , so that it looks like@interface AppDelegate : PhoneGapDelegate {

    NSString* invokeString;

    GADBannerView *bannerView_;

    }

  5.  In AppDelegate.m –  #define MY_BANNER_UNIT_ID @”Your AdMob Publisher ID”

  6. Add the following code at the beginning of webViewDidFinishLoad:    bannerView_ = [[GADBannerView alloc]init];

    [bannerView_ setDelegate:self];

    [bannerView_ setFrame:CGRectMake(0, 45, 320, 95)];//Position of Ad banner

    bannerView_.adUnitID = MY_BANNER_UNIT_ID;

    bannerView_.rootViewController = self.viewController;

    [self.viewController.view addSubview:bannerView_];

    [bannerView_ loadRequest:[GADRequest request]];

You can find the sample code here