- Open the phonegap project to which AdMob is to be added.
- Import GoogleAdMobAdsSDK which can be found here.
- 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".
- In AppDelegate.h import "GADBannerView.h" and add "GADBannerView *bannerView_;" , so that it looks like@interface AppDelegate : PhoneGapDelegate {
NSString* invokeString;
GADBannerView *bannerView_;
} - In AppDelegate.m – #define MY_BANNER_UNIT_ID @”Your AdMob Publisher ID”
- 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
Comments
Post a Comment