如何解决Admob ( GoogleMobileAds 8.0.0 ) iOS SDK - 未找到 GADInterstitial API,请问如何使用 GADInterstitialAd - 示例代码?
下面一行没有错误
#import <GoogleMobileAds/GoogleMobileAds.h>
但是没有检测到 Admob API...它对所有 admob API 都给出了错误。检测到另一个 SDK(Applovin) API。
这是截图。如何修复 Admob/GoogleMobileAds?
解决方法
AdMob 刚刚对 8.0.0 进行了一次重大版本更新,其中包含多项 API 更改。
要么
- 使用
pod 'Google-Mobile-Ads-SDK','~> 7.69'
将 pod 锁定到 7.x - 执行 https://developers.google.com/admob/ios/migration 中记录的 8.x 迁移
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")
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。