Search code examples
iosobjective-cxcodecocos2d-iphoneadmob

Admob Interstitial Cocos2d Objective C


i'm searching on google but i only find the way to integrate the AdMob Banner View on my app in Cocos2d. Now I need to put the full screen AdMob interstitial and i don't find the way to do it :. Please Help me, how i can do it??

I'm not sure what source code i need to post... I would like to show the interstitial when the app startup and when there is the game over.

I already tried this

but it gave me some error.


Solution

  • In AppDelegate.h, add GADInterstitialDelegate

    @interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate, GADInterstitialDelegate>
    {
    }
    -(void)showAdmobFullScreenAds;
    @end
    
    #define App ((AppController *)[[UIApplication sharedApplication] delegate])
    

    In AppDelegate.m

    -(void)showAdmobFullScreenAds
    {
        GADInterstitial  *interstitial_ = [[GADInterstitial alloc] init];
        interstitial_.adUnitID = @"ca-app-pub-YOUR_ID";
        interstitial_.delegate = self;
        [interstitial_ loadRequest:[GADRequest request]];
    
    }
    
    - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
    {
        [interstitial presentFromRootViewController:[CCDirector sharedDirector]];
    }
    

    // In GameOver class, add #import "AppDelegate.h" then use below function

       [App showAdmobFullScreenAds];