Shazron's Cordova (aka PhoneGap) Blog

at Adobe Systems Inc.

PhoneGap iAds Plugin

with 22 comments

Hey its a new plugin for PhoneGap. I call it the “PhoneGap AdPlugin”, and even though it only supports iAds currently, there is potential for supporting the other ad networks as a backup to iAds. Make sure you read the RELEASE NOTES in the README for limitations.

Get the source and view the README

Below are screenshots from the test app included, called ‘iAdHost’


Written by shazron

July 12, 2010 at 9:25 am

Posted in phonegap

22 Responses

Subscribe to comments with RSS.

  1. Great! Thank u very much!

    Daniel Kim

    July 13, 2010 at 1:28 am

  2. Great news! Do you need the ‘edge’ version of phonegap to get this working or will plug-ins work on the current 1.9.1 release?

    Jimmy Fountain

    July 13, 2010 at 3:26 pm

    • Should work with current release.


      July 13, 2010 at 4:04 pm

  3. Could you post your HTML for the Phonegap HTML file shown in the windows above?


    July 16, 2010 at 5:31 am

  4. The Apple iAd docs ( says “While an advertisement is displayed, your application’s activities should be scaled back, and features that require the user to see or hear the user interace should be suspended.”.

    How can I detect that the ad was clicked so I can pause the game music I have playing and pause the game?


    August 8, 2010 at 3:02 pm

    • @russ
      Might be in the next feature update – I have to hook into the native callbacks and send out DOM events to the UIWebView.


      August 27, 2010 at 9:44 am

  5. How can i check when Advertisements are Not Available ?


    September 4, 2010 at 3:49 pm

  6. @Giulio
    Check out the updated code, and www/index.html – it should handle that event.


    October 8, 2010 at 10:58 pm

  7. @Shazron, thanks for your reply. I’ll try it 😉


    October 9, 2010 at 11:02 am

  8. Hi Shazron,

    thanks for a great plugin, problem is I can’t get the demo project to compile ;(

    I’ve followed the readme to the letter, a handful of times, the project zip is here:

    The error I’m getting is:
    cp ../*.js /Users/imacapple/Work/iAdHost/www/
    cp: ../*.js: No such file or directory

    And I really can’t see what I’m doing wrong… would you mind taking a look please? It would be a great help.

    I saw this guide – should I be making these changes also:

    Thanks a lot


    Jamie McDonnell

    October 28, 2010 at 8:08 pm

    • The demo project is just that, a demo.
      If you created a new project and did what you did according to the readme, it should be fine.
      Don’t use iAdHost as your base.


      October 28, 2010 at 9:43 pm

  9. Anyone know of any support for YOC Network and Phonegap?


    February 7, 2011 at 5:47 pm

  10. Is it possible to show iAds using Sencha + Phonegap + PhoneGap AdPlugin ?


    June 23, 2011 at 5:09 pm

    • Yeah, the iAds plugin is outside of the WebView.


      June 24, 2011 at 10:38 pm

  11. Hi Shazron,

    I followed all steps, but nothing is showing up. No errors. The app works fine, but I don’t see the ad. What could I be doing wrong?

    Thank you!


    September 21, 2011 at 6:26 am

    • Don’t know really. I’ve often had the problem — Apple is just not serving ads even the test ones sometimes.


      September 22, 2011 at 11:23 pm

  12. HI,
    Thanks for the tut but one question:
    How do get the ads to show up below my app and not ontop of it, I have a row of buttons on the bottom of my app but the ads show up on top of them thereby blocking them from the view and use. If I just add an extra 50px to the bottom of my app then that is wasted space if there is no app to show.

    here is what my appdelagate.h and .m look like now:
    #import “iAd/iAd.h”

    @interface AppDelegate : PhoneGapDelegate {
    NSString* invokeString;
    BOOL bannerIsVisible;

    @property (copy) NSString* invokeString;
    @property (nonatomic,retain) IBOutlet ADBannerView *adView;
    @property BOOL bannerIsVisible;

    and .m:
    @implementation AppDelegate

    @synthesize invokeString;
    @synthesize adView;
    //@property (nonatomic,retain) IBOutlet ADBannerView *adView;
    @synthesize bannerIsVisible;

    – (void)webViewDidFinishLoad:(UIWebView *)theWebView
    // only valid if DromeiOS.plist specifies a protocol to handle
    // this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
    NSString* jsString = [NSString stringWithFormat:@”var invokeString = \”%@\”;”, self.invokeString];
    [theWebView stringByEvaluatingJavaScriptFromString:jsString];
    bannerIsVisible = YES;
    //ADBannerView * ############ NOTICE THIS CHANGE ############
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectMake(0, 410, 320, 50); // if you want the banner to be on top of the screen remove this line
    adView.delegate = self;
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;//ADBannerContentSizeIdentifier320x50;
    [theWebView addSubview:adView];
    return [ super webViewDidFinishLoad:theWebView ];



    October 3, 2011 at 6:44 pm

    • ok, I added code to my showAd methoid to show/hide an extra div at the bottom of my app if showAd(true) is called, trouble is even if showAd(false) is called the ad banner still pops up (test ad) and my div.hide() gets called and my buttons are hidden again. Is there a more reliable way to detect when the ad banner is shown and when it is hidden?


      October 4, 2011 at 4:52 pm

  13. Is there a way to get the ads to just appear by default without clicking the checkbox? I’m really new at app development so this may be a really easy/stupid question. But if there is a checkbox to display/not display the ads, won’t users of the app just leave the box unchecked? Plus it doesn’t make the application look too nice.

    Any help would greatly be appreciated.


    December 3, 2011 at 2:27 pm

  14. Hi, thanks for the iAd plugin. I was wondering if there is a way to control the placement of the Ad, (i am not talking about top or bottom). My application has 3 pages(or views using jQm) and i am interested in showing the Ads on the bottom of all pages except the first page. is there a way to do that? can you guide me?
    this is for an iPhone app only for now


    March 31, 2012 at 6:10 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: