iPhoneProcessor
iPhoneProcessor

Reputation: 5130

Admob ( GoogleMobileAds 8.0.0 ) iOS SDK - GADInterstitial API not found, How to use GADInterstitialAd - sample code please?

No error for below line

#import <GoogleMobileAds/GoogleMobileAds.h>

But none of Admob API detected…Its giving error for all admob API. Another SDK(Applovin) API detected.

Here is screenshots. How to fix Admob/GoogleMobileAds ?

enter image description here enter image description here Pod File: enter image description here

Upvotes: 1

Views: 3059

Answers (4)

mintymuz
mintymuz

Reputation: 357

If you are NOT seeing the following warning in your list of imports:

No such module GoogleMobileAds

...yet you ARE seeing the following warning elsewhere in your code:

Cannot find type GADInterstitialAd in scope

...check that you are not muddling the implementation for v7 and v8 of the Google-Mobile-Ads-SDK SDK.

  • v7 uses GADInterstitial
  • v8 uses GADInterstitialAd

https://developers.google.com/admob/ios/migration

By default, even if you don't specify a version in your Podfile, you may find that v7 is what has been downloaded; yet Google's documentation gives you the instructions for implementing v8.

Upvotes: 0

Guru
Guru

Reputation: 22042

GoogleMobileAds 8.0.0 iOS GADInterstitialAd FullScreen Ads Code:

// In .h File

#import <GoogleMobileAds/GoogleMobileAds.h>

@interface AppController : NSObject <GADFullScreenContentDelegate>

@property(nonatomic, strong) GADInterstitialAd *interstitial;

// In .m file

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [self loadAdmob_Ads];
}

-(void)loadAdmob_Ads
{
    GADRequest *request = [GADRequest request];
    [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-Your_Interstitial_Ad_Unit_ID"
                                    request:request
                          completionHandler:^(GADInterstitialAd *ad, NSError *error)
    {
      if (error)
      {
            #ifdef COCOS2D_DEBUG
                NSLog(@"\nAdmob Failed to load interstitial ad with error: %@", [error localizedDescription]);
            #endif
          return;
      }
      self.interstitial = ad;
      self.interstitial.fullScreenContentDelegate = self;
    }];
}

// Call showAdmobAdsFullScreen whenever you want to show fullscreen ads

-(void)showAdmobAdsFullScreen
{
        if (self.interstitial) {
            [self.interstitial presentFromRootViewController:self.viewController];
          }
        else
        {
            #ifdef COCOS2D_DEBUG
                NSLog(@"\nAdmob Ad wasn't ready\n");
            #endif
        }
}

// admob delegates

- (void)adDidPresentFullScreenContent:(id)ad {
       
        #ifdef COCOS2D_DEBUG
               NSLog(@"\nAdmob ad did present full screen content.\n");
        #endif
       
   }

   - (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
       
        #ifdef COCOS2D_DEBUG
               NSLog(@"Admob Ad failed to present full screen content with error %@.", [error localizedDescription]);
        #endif
       
   }

   - (void)adDidDismissFullScreenContent:(id)ad {
       
       [self loadAdmob_Ads]; 
       
        #ifdef COCOS2D_DEBUG
            NSLog(@"Admob Ad did dismiss full screen content.");
        #endif           
   }

Upvotes: 1

nullproduction
nullproduction

Reputation: 606

Example of using GADInterstitialAd in GoogleMobileAds 8.0 (Admob iOS)

import UIKit
import GoogleMobileAds

class ViewController: UIViewController, GADFullScreenContentDelegate {
    
    var ad: GADInterstitialAd!
  
    override func viewDidLoad() {
        super.viewDidLoad()
        loadAd()
    }
  
    func loadAd() {
       let id = "ca-app-pub-3940256099942544/4411468910"
       GADInterstitialAd.load(withAdUnitID: id, request: GADRequest()) { ad, error in
            if error != nil { return }
            self.ad = ad
            self.ad.fullScreenContentDelegate = self
            self.ad.present(fromRootViewController: self)
        }
    }
  
    func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
        print("present-ads")
    }
    
    func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
        print("dismiss-ads")
    }
  
}

Upvotes: 1

Paul Beusterien
Paul Beusterien

Reputation: 29592

AdMob just did a major version update to 8.0.0 with several API changes.

Either

Upvotes: 2

Related Questions