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

你。 提交于 2021-02-05 09:24:09

问题


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 ?

Pod File:


回答1:


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

Either

  • Lock the pod to 7.x with pod 'Google-Mobile-Ads-SDK', '~> 7.69'
  • Do the 8.x migration documented at https://developers.google.com/admob/ios/migration



回答2:


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]; // not sure this line...may not needed!!!
       
        #ifdef COCOS2D_DEBUG
            NSLog(@"Admob Ad did dismiss full screen content.");
        #endif           
   }



回答3:


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")
    }
  
}


来源:https://stackoverflow.com/questions/66031155/admob-googlemobileads-8-0-0-ios-sdk-gadinterstitial-api-not-found-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!