以下行没有错误
#import <GoogleMobileAds/GoogleMobileAds.h>
但是没有检测到任何 Admob API……它对所有 admob API 都给出了错误。检测到另一个 SDK(Applovin) API。
这是屏幕截图。如何修复 Admob/GoogleMobileAds ?
以下行没有错误
#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'
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")
}
}
如果您在导入列表中没有看到以下警告:
没有这样的模块
GoogleMobileAds
...但是您在代码的其他地方看到以下警告:
GADInterstitialAd
在范围内找不到类型
Google-Mobile-Ads-SDK
...检查您没有混淆SDK的 v7 和 v8 的实现。
GADInterstitial
GADInterstitialAd
https://developers.google.com/admob/ios/migration
默认情况下,即使你没有在 Podfile 中指定版本,你也可能会发现下载的是 v7;然而 Google 的文档为您提供了实施 v8 的说明。