Admob ( GoogleMobileAds 8.0.0 ) iOS SDK - 未找到 GADInterstitial API,请问如何使用 GADInterstitialAd - 示例代码?

问题描述

下面一行没有错误

#import <GoogleMobileAds/GoogleMobileAds.h>

但是没有检测到 Admob API...它对所有 admob API 都给出了错误。检测到另一个 SDK(Applovin) API。

这是截图。如何修复 Admob/GoogleMobileAds?

enter image description here

enter image description here

豆荚文件:

enter image description here

解决方法

AdMob 刚刚对 8.0.0 进行了一次重大版本更新,其中包含多项 API 更改。

要么

,

GoogleMobileAds 8.0.0 iOS GADInterstitialAd 全屏广告代码:

// 在 .h 文件中

#import <GoogleMobileAds/GoogleMobileAds.h>

@interface AppController : NSObject <GADFullScreenContentDelegate>

@property(nonatomic,strong) GADInterstitialAd *interstitial;

// 在 .m 文件中

- (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;
    }];
}

// 每当您想显示全屏广告时调用 showAdmobAdsFullScreen

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

// admob 代表

- (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           
   }
,

在 GoogleMobileAds 8.0 (Admob iOS) 中使用 GADInterstitialAd 的示例

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...