Subject: [PhoneGap] SOLVED: Adding AdMob Ads Natively (no
plugins required) for iOS

I want to share this with the group because it seems that these
directions don't exist ANYWHERE. I'm not really sure what the big
secret is but I want to de-mystify it and hopefully save some others
precious time. It's really simple and Does Not involve installing any
phonegap plugins ;)

1.) Create your normal, everyday phonegap (1.0.0) project in xcode
2.) Import the GoogleAdMobAdsSDK folder and the required AdMob
frameworks (I believe the only one that wasn't already in the phonegap
project was MessageUI.framework)
3.) In AppDelegate.h - #import "GADBannerView.h" & add GADBannerView
*bannerView_; to your @interface
4.) In AppDelegate.m - #define MY_BANNER_UNIT_ID @"Your AdMob
Publisher ID# Here"

Now the tricky part. This caused me to bang my head on the wall for
some time . . .

5.) Change your method webViewDidFinishLoad to this . . .

- (void)webViewDidFinishLoad:(UIWebView *)theWebView
bannerView_ = [[GADBannerView alloc]init];
[bannerView_ setDelegate:self];
[bannerView_ setFrame:CGRectMake(0, 430, 320, 50)];

// Specify the ad's "unit identifier." This is your AdMob
Publisher ID.
bannerView_.adUnitID = MY_BANNER_UNIT_ID;

// Let the runtime know which UIViewController to restore after
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self.viewController;
[self.viewController.view addSubview:bannerView_];

// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];

// only valid if AdGap.plist specifies a protocol to handle
// this is passed before the deviceready event is fired, so you
access it in js when you receive deviceready
NSString* jsString = [NSString stringWith...

invokeString =
\"%@\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
return [ super webViewDidFinishLoad:theWebView ];

That's it.

I have created a sample project that does exactly this with the option
to display test ads.
You can download the project from

Why does the banner view need to be created in the
webViewDidFinishLoad method? I think it's because phonegap doesn't
create the viewController until after the webview but I might be
wrong. This might not be the ideal solution for everyone's app but it
works for me. Enjoy.

You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at

For more info on PhoneGap or to download the code go to

Programming list archiving by: Enterprise Git Hosting