Efi Debi
Efi Debi

Reputation: 61

Intrerstitial ads using AdMob plugin with phonegap for iOS

I'm using this AdMob plugin for phonegap and it is working perfectly? You ca read here how I did it if you need. My question is how to use this plugin to create an interstitial ads (that take over the entire screen) for my iOS app?

Thank you for your help!

Upvotes: 0

Views: 1199

Answers (1)

RajPara
RajPara

Reputation: 2281

So it looks like you'll have to write your own code to get interstitials to work. Looking at that plugin it looks like it works only for banners. Don't know how familiar you are with Objective C development but I can try to give you a high level overview of the implementation.

You can just create a new plugin if you want or add this to the existing plugin. Just throwing this down off the top of my head so doubt it's going to work without compilation errors, etc:

- (void) createInterstitial:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options
{
    NSLog(@"Create Interstitial executed");
    // Make sure you create an adInterstitial property
    if(self.adInterstitial)
        return;

    if([options objectForKey:@"siteId"])
    {
        NSLog(@"Setting site Id");
        self.siteId=[[options objectForKey:@"siteId"] description];
    }

    // Note that the GADBannerView checks its frame size to determine what size
    // creative to request. 
    //Initialize the banner off the screen so that it animates up when displaying
    self.adInterstitial = [[[GADInterstitial alloc] init] autorelease];
    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
    // before compiling.
    self.adInterstitial.adUnitID = self.siteId;
    self.adInterstitial.delegate = self;

}

- (void) loadInterstitial:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{    
    NSLog(@"Load interstitial executed");
    if(!self.adInterstitial)
        [self createInterstitial:arguments withDict:options];

    GADRequest *request = [self createRequest];
    [self setLocation:&request withDict:options];
    [self.adInterstitial loadRequest:request];
}

- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    [interstitial presentFromRootViewController:self];
    [self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.AdMob.adViewDidReceiveAdCallback();"];

}

- (void)interstitial:(GADInterstitial *)interstitial
    didFailToReceiveAdWithError:(GADRequestError *)error {
    NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
    NSString* jsString = [NSString stringWithFormat:@"window.plugins.AdMob.didFailToReceiveAdWithErrorCallback(%@);", 
                          [error localizedFailureReason]];
    [self.webView stringByEvaluatingJavaScriptFromString:jsString];
}

Upvotes: 0

Related Questions