How to integrate fullscreen admob ads in ios

#pragma mark GADInterstitialDelegate implementation

  • (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
        [self.loadingSpinner stopAnimating];
         NSLog(@“interstitialDidReceiveAd”);
     //   self.showInterstitialButton.enabled = YES;
    }

  • (void)interstitial:(GADInterstitial *)interstitial
    didFailToReceiveAdWithError:(GADRequestError *)error {
        
        [self.loadingSpinner stopAnimating];
        
        NSLog(@“interstitial error”);
    // [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(loadInterstitial) userInfo:nil repeats:NO];
        // Alert the error.
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@“GADRequestError”
                                                        message:[error localizedDescription]
                                                       delegate:nil
                                              cancelButtonTitle:@“Drat”
                                              otherButtonTitles:nil];
        [alert show];
        
      //  self.showInterstitialButton.enabled = NO;
    }

#pragma mark GADRequest implementation

  • (GADRequest *)request {
        GADRequest *request = [GADRequest request];
        NSLog(@“GADRequest request”);

// Make the request for a test ad. Put in an identifier for the simulator as well as any devices
    // you want to receive test ads.
    request.testDevices = @[
                            // TODO: Add your device/simulator test identifiers here. Your device identifier is printed to
                            // the console when the app is launched.
                            GAD_SIMULATOR_ID
                            ];
    return request;
}

#pragma mark Insterstitial button actions

  • (void)loadInterstitial:(NSObject *)prms {
        // Create a new GADInterstitial each time.  A GADInterstitial will only show one request in its
        // lifetime. The property will release the old one and set the new one.
        if ( [[UIDevice currentDevice].systemVersion floatValue]>6.5)
        {

NSDictionary parameters = (NSDictionary)prms;
    NSLog(@“Passed params are : %@”, parameters);
    
    // Fetching the name of the method to be called from Native to C++
    // For a ease of use, i have passed the name of method from C++
    NSString* CPPFunctionToBeCalled = (NSString*)[parameters objectForKey:@“to_be_called”];

self.interstitial = [[GADInterstitial alloc] init];
    
    self.interstitial.autorelease;
    self.interstitial.delegate = self;
    
    // Note: Edit SampleConstants.h to update kSampleAdUnitId with your interstitial ad unit id.
    self.interstitial.adUnitID = kSampleAdUnitID;
    [self.interstitial loadRequest:[self request]];
    
    [self.loadingSpinner startAnimating];
    
    }

}

  • (void)showInterstitial:(NSObject )prms {
       // self.showInterstitialButton.enabled = NO;
        if ( [[UIDevice currentDevice].systemVersion floatValue]>6.5)
        {
        NSLog(@“showInterstitial”);
        // Show the interstitial.
        //[self.interstitial presentFromRootViewController:self];
        NSDictionary parameters = (NSDictionary)prms;
        NSLog(@“Passed params are : %@”, parameters);
        
        // Fetching the name of the method to be called from Native to C++
        // For a ease of use, i have passed the name of method from C++
       NSString
    CPPFunctionToBeCalled  = (NSString*)[parameters objectForKey:@“to_be_called”];
        
        
        if (self.interstitial!=Nil&&!self.interstitial.hasBeenUsed)
        {
            
            [self.interstitial presentFromRootViewController:self];
            
        }else
        {
        }

}
}
/// Store from a link on the interstitial).

  • (void)interstitialWillPresentScreen:(GADInterstitial *)ad
    {
          NSLog(@“RootViewController interstitialWillPresentScreen”);
      // CCDirector::sharedDirector()->stopAnimation();
    }

/// Called before the interstitial is to be animated off the screen.

  • (void)interstitialWillDismissScreen:(GADInterstitial *)ad
    {
          NSLog(@“RootViewController interstitialWillDismissScreen”);
       //  CCDirector::sharedDirector()->startAnimation();
    }
  • (void)interstitialDidDismissScreen:(GADInterstitial *)ad
    {
        //An interstitial object can only be used once - so it’s useful to automatically load a new one when the current one is dismissed
        //self.view.userInteractionEnabled=YES;
       // NSLog(@“interstitialDidDismissScreen :%@”,@“showInterstitial”);
      //  [IOSNDKHelper SendMessage:@“showInterstitial” WithParameters:nil];
        [self cleanupInterstitial];
       
        //  [IOSNDKHelper SendMessage:@“showInterstitial” WithParameters:nil];
    }
    -(void)showBannerAD:(NSObject *)prms
    {
          NSLog(@“RootViewController showBannerAD”);
        [[BannerViewController instance] setHidden:NO];
    }
    -(void) hideBannerAD:(NSObject *)prms
    {
        NSLog(@“RootViewController hideBannerAD”);

[[BannerViewController instance] setHidden:YES];
}

  • (void)cleanupInterstitial {
        self.interstitial.delegate = nil;
        self.interstitial = nil;
    }

call loadInterstitial method from cpp code before calling showInterstitial method to show the fullscreen ads in cocos2dx game .


https://developers.google.com/mobile-ads-sdk/download#download
https://github.com/googleads/googleads-mobile-ios-examples/tree/master/admob/InterstitialExample

@Ankush_S this isnt making much sense. Can you explain whats going on here? And how to call these methods from c++

Ankush can you please explain your code. for newbie like me it seem matrix code hard to break into :slight_smile:

Hello

You can use our Cocos Helper which has AdMob supports with simple and easy to follow integration videos http://sonarsystems.co.uk/cocoshelper.php

Kind regards
Frahaan Hussain - CEO

You can use our Cocos Helper which has AdMob supports with simple and easy to follow integration videos http://sonarsystems.co.uk/cocoshelper.php

Kind regards
Frahaan Hussain - CEO

@muhammadsaad @alixc @Ankush_S

You can use our Cocos Helper which has AdMob support with simple and easy to follow integration videos http://sonarsystems.co.uk/cocoshelper.php