این صفحه مهاجرت های نسخه فعلی و قبلی را پوشش می دهد.
از نسخه 9 به نسخه 10 مهاجرت کنید
تبلیغات در iOS 11 متوقف می شود
حداقل نسخه iOS که Google Mobile Ads SDK نسخه 10.0.0 برای آن تبلیغات ارائه می کند، iOS 12 است.
ارتقاء به Google Mobile Ads SDK نسخه 10.0.0 برنامه شما را در دستگاههای iOS 11 و iOS 10 خراب نمیکند، با این حال، هیچ تبلیغی در آن دستگاهها نمایش داده نمیشود.
ساخت با بیت کد دیگر پشتیبانی نمی شود
اکنون برای ادغام Google Mobile Ads SDK، غیرفعال کردن بیت کد در برنامه های تلفن همراه شما لازم است.
انواع حذف شده است
تایپ کنید | یادداشت |
---|---|
GADGender | بدون جایگزینی |
پروتکل GADMRewardBasedVideoAdNetworkAdapter | همه آداپتورهای واسطهای پاداشدار فهرستشده در Choose Networks استفاده از این پروتکلها را برای بیش از یک سال متوقف کردهاند. از GADMediationAdapter برای میانجیگری و رویدادهای سفارشی استفاده کنید. |
پروتکل GADMRewardBasedVideoAdNetworkConnector |
خواص حذف شد
ویژگی های زیر بدون جایگزینی حذف می شوند.
کلاس v10.0.0 | ویژگی |
---|---|
GADMediationAdRequest | تولد کاربر |
userGender | |
userHasLocation | |
userLatitude | |
طول کاربر | |
userLocationAccuracyInMeters | |
userLocationDescription | |
GADCustomEvent Request | userHasLocation |
userLatitude | |
طول کاربر | |
userLocationAccuracyInMeters | |
userLocationDescription |
از نسخه 8 به نسخه 9 مهاجرت کنید
تبلیغات در iOS 10 متوقف می شود
حداقل نسخه iOS که Google Mobile Ads SDK نسخه 9.0.0 پشتیبانی می کند iOS 11 است.
ارتقاء به Google Mobile Ads SDK نسخه 9.0.0 برنامه شما را در دستگاههای iOS 10 خراب نمیکند، اما هیچ تبلیغی در آن دستگاهها نمایش داده نمیشود.
اجرای دقیق تر کنترل های نوار وضعیت
با شروع از نسخه 9.0.0، هنگامی که تبلیغات با فرمت تمام صفحه را ارائه می کنید، برنامه شما باید اطمینان حاصل کند که تبلیغات قادر به کنترل نمایش نوار وضعیت هستند. اگر این کار را انجام ندهید، یک پیغام خطا در گزارش ها مشاهده خواهید کرد.
بسته به طرحبندی خاص کنترلکنندههای نمایش در برنامهتان، ممکن است نیازی به ایجاد هیچ تغییری برای اطمینان از این نداشته باشید. در نظر بگیرید که آیا باید ویژگی childViewControllerForStatusBarHidden
را در rootViewController
آگهی خود تنظیم کنید.
تغییر نام adDidPresentFullScreenContent: به adWillPresentFullScreenContent:
هیچ تغییر رفتاری وجود ندارد. روش delegate درست قبل از ارائه آگهی فراخوانی می شود، بنابراین نام روش جدید عملکرد آن را بهتر نشان می دهد.
API تنظیم مکان را در GADRequest حذف کنید
- (void)setLocationWithLatitude:longitude:accuracy:
از GADRequest
حذف شده است زیرا اطلاعات مکان توسط Google برای هدفیابی تبلیغات استفاده نمیشود. در صورت لزوم از API های شخص ثالث برای ارائه اطلاعات به شبکه های تبلیغاتی شخص ثالث استفاده کنید.
منسوخ شدن رابط های رویداد سفارشی
رویدادهای سفارشی ناشران را با استفاده از AdMob Mediation قادر میسازند تا میانجیگری آبشار را برای یک شبکه تبلیغاتی که یکی از شبکههای تبلیغاتی پشتیبانیشده نیست اضافه کنند.
همه پروتکل های رویداد سفارشی منسوخ شده اند. در عوض، از پروتکلهای GADMediationAdapter
و GADMediationAdEventDelegate
موجود برای دستیابی به عملکردهای مشابه استفاده کنید. این تغییر وضوح را بهبود میبخشد و شما را قادر میسازد رویدادهای سفارشی را برای آگهیهای دارای پاداش و آگهیهای بین اسکرولری که قبلاً در دسترس نبودند ایجاد کنید.
API ها
جدول زیر APIهای آداپتور میانجی مربوط به APIهای رویدادهای سفارشی را فهرست میکند که باید از نسخه 9.0.0 استفاده شوند.
v8 | v9 | |
---|---|---|
GADCustomEventBanner GADCustomEventInterstitial GADCustomEventNativeAd | GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediationRewardedAd GADMediationNativeAd |
delegate | Delegate توسط کنترل کننده تکمیل بار هر تابع بار از کلاس GADMediationAdapter برگردانده می شود. | |
-init | -init | |
-requestBannerAd:parameter: label:request: | -loadBannerForAdConfiguration: completionHandler: | |
-requestInterstitialAdWith Parameter:label:request: | -loadInterstitialFor AdConfiguration: completionHandler: | |
-requestNativeAdWithParameter: request:adTypes:options: rootViewController: | -loadNativeAdFor AdConfiguration: completionHandler: | |
N/A | -loadInterscrollerAdFor AdConfiguration: completionHandler: | |
N/A | -loadRewardedAdFor AdConfiguration: completionHandler: | |
-presentFromRootViewController: | -presentFromViewController: | |
-handlesUserClicks | -handlesUserClicks | |
-handlesUserImpressions | -handlesUserImpressions |
روش های تفویض اختیار
جدول زیر روشهای انتقال رویداد آگهی میانجیگری مربوط به روشهای واگذاری رویداد سفارشی را فهرست میکند که باید از نسخه 9.0.0 استفاده شوند.
v8 | v9 | |
---|---|---|
GADCustomEventBannerDelegate GADCustomEventInterstitialDelegate GADCustomEventNativeAdDelegate | GADMediationAdEvent Delegate | GADMediationAd |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd: | وضعیت بار آگهی در کنترل کننده تکمیل بار هر تابع بار در کلاس GADMediationAdapter گنجانده شده است. | |
-customEventBanner:didFailAd: -customEventInterstitial:didFailAd: | ||
-customEventBannerWasClicked: -customEventInterstitialWasClicked: | -reportClick | |
-customEventBannerWill PresentModal: -customEventInterstitialWill PresentModal: | -willPresentFullScreenView | |
-customEventBannerWill DismissModal: -customEventInterstitialWill DismissModal: | -willDismissFullScreenView | |
-customEventBannerDid DismissModal: -customEventInterstitialDid DismissModal: | -didDismissFullScreenView | |
-customEventBannerWill LeaveApplication: -customEventInterstitialWill LeaveApplication: | -willBackgroundApplication | |
viewControllerFor PresentingModalView | -[GADMediationBannerAd view] |
سایر روش ها و ثابت های حذف/جایگزین شده
تغییرات در روش، ثابت یا ویژگی | |
---|---|
kGAD- ثابت های پیشوند | حذف شده. از ثابت های پیشوند GAD- استفاده کنید. |
GADAdNetworkResponseInfo | credentials حذف شد به جای آن از adUnitMapping استفاده کنید. |
GADCustomNativeAd | mediaView در GADCustomNativeAd منسوخ شده است. به جای آن mediaContent استفاده کنید. |
APIهای خرید درون برنامه ای در GoogleMobileAds | APIهای inAppPurchase در GoogleMobileAds حذف شدند. |
از نسخه 7 به نسخه 8 مهاجرت کنید
Google 移动广告 SDK 版本 8.0.0 引入了一些重大更改,并且重命名了一些 API 。
关于全屏广告格式 API 的更新
从版本 8.0.0 开始,插页式广告和激励广告采用通用的全屏广告样式,旨在提高一致性。这些新的全屏广告 API 与版本 7 的全屏广告 API 有两大主要区别:
静态类方法
load
:之前加载/展示全屏广告的方式如下:
- 创建广告对象实例并保留对该实例的引用。
- 分配一个处理加载和显示回调的委托。
- 加载广告。
- 使用
isReady
检查广告是否已加载。 - 展示广告。
在版本 8 中,该方法会略有变化。加载回调不再是委托的一部分。而是作为完成处理程序传入
load
方法:- 对广告类调用静态加载方法,并提供加载完成处理程序。
- 在加载完成回调函数中,保留对返回的已加载广告的引用。
- 指定用于处理节目回调的代理。
- 展示广告。
新方法具有以下优势:
- 您永远都不会引用未加载的广告。
- 广告加载期间,您无需保留广告对象。
一致的广告事件。
事件类型 现有 API v8 中的 API 加载事件 GADInterstitialDelegate
或GADRewardedAdDelegate
GADInterstitialAdLoadCompletionHandler
或GADRewardedAdLoadCompletionHandler
展示事件 GADFullScreenContentDelegate
以前,要监听任何广告事件,您需要注册一个对插页式广告的委托属性实现
GADInterstitialDelegate
协议的类,或者注册一个用于对激励广告的委托属性实现GADRewardedAdDelegate
协议的类,具体取决于您使用的是哪种格式。同一委托具有与广告的加载和展示生命周期相关的方法。在版本 8 中,加载和展示事件是分开的。现在,您可以在展示广告之前随时注册
GADFullScreenContentDelegate
,而无需在加载广告之前设置单个代理。每种广告格式特有的广告加载事件将移至加载方法中传递的单个加载完成处理程序。
插页式广告
加载广告
以下代码段展示了如何加载插页式广告并监听广告加载成功或失败的事件。
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: GADInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/44118910") interstitial.delegate = self let request = GADRequest() interstitial.load(request) } /// Tells the delegate an ad request succeeded. func interstitialDidReceiveAd(_ ad: GADInterstitial) { print("Interstitial ad loaded.") } /// Tells the delegate an ad request failed. func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) { print("Interstitial ad failed to load with error: \(error.localizedDescription)") } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADInterstitial *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/44118910"]; self.interstitial.delegate = self; GADRequest *request = [GADRequest request]; [self.interstitial loadRequest:request]; } /// Tells the delegate an ad request succeeded. - (void)interstitialDidReceiveAd:(GADInterstitial *)ad { NSLog(@"Insterstitial ad loaded."); } /// Tells the delegate an ad request failed. - (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"Interstitial ad failed to load with error: %@", [error localizedDescription]); }
v8
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADFullScreenContentDelegate { var interstitial: GADInterstitialAd? override func viewDidLoad() { super.viewDidLoad() let request = GADRequest() GADInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738", request: request, completionHandler: { (ad, error) in if let error = error { print("Failed to load interstitial ad with error: \(error.localizedDescription)") return } self.interstitial = ad self.interstitial.fullScreenContentDelegate = self } ) } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADInterstitialAd *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GADRequest *request = [GADRequest request]; [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/44118910" request:request completionHandler:^(GADInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]); return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; }
展示广告
v7
Swift
func showInterstitial() { ... if interstitial.isReady { interstitial.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showInterstitial: { ... if (self.interstitial.isReady) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
v8
Swift
func showInterstitial() { ... if let ad = interstitial { ad.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showInterstitial: { ... if (self.interstitial) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
展示广告事件
以下代码段展示了如何在广告展示(成功或失败)以及关闭时处理回调。
v7
Swift
override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/44118910") interstitial.delegate = self ... } /// Tells the delegate that an interstitial will be presented. func interstitialWillPresentScreen(_ ad: GADInterstitial) { print("Interstitial ad will be presented.") } /// Tells the delegate the interstitial is to be animated off the screen. func interstitialWillDismissScreen(_ ad: GADInterstitial) { print("Interstitial ad will be dismissed.") } /// Tells the delegate the interstitial had been animated off the screen. func interstitialDidDismissScreen(_ ad: GADInterstitial) { print("Interstitial ad dismissed.") } /// Tells the delegate that a user click will open another app /// (such as the App Store), backgrounding the current app. /// /// This is not a reliable callback for an ad click event and is removed in /// version 8. If you wish to listen to an ad causing a user to leave the app, /// use applicationWillResignActive: or sceneWillResignActive: instead. func interstitialWillLeaveApplication(_ ad: GADInterstitial) { print("Interstitial ad will leave application.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:"ca-app-pub-3940256099942544/44118910"]; self.interstitial.delegate = self; ... } /// Tells the delegate that an interstitial will be presented. - (void)interstitialWillPresentScreen:(GADInterstitial *)ad { NSLog(@"Interstitial ad will be presented."); } /// Tells the delegate the interstitial is to be animated off the screen. - (void)interstitialWillDismissScreen:(GADInterstitial *)ad { NSLog(@"Interstitial ad will be dismissed."); } /// Tells the delegate the interstitial had been animated off the screen. - (void)interstitialDidDismissScreen:(GADInterstitial *)ad { NSLog(@"Interstitial ad dismissed."); } /// Tells the delegate that a user click will open another app /// (such as the App Store), backgrounding the current app. /// /// This is not a reliable callback for an ad click event and is removed in /// version 8. If you wish to listen to an ad causing a user to leave the app, /// use applicationWillResignActive: or sceneWillResignActive: instead. - (void)interstitialWillLeaveApplication:(GADInterstitial *)ad { NSLog(@"Interstitial ad will leave application."); }
v8
Swift
override func viewDidLoad() { super.viewDidLoad() let request = GADRequest() GADInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738", request: request, completionHandler: { (ad, error) in if let error = error { print(error.localizedDescription) return } self.interstitial = ad self.interstitial.fullScreenContentDelegate = self } ) } func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Ad did present full screen content.") } func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) { print("Ad failed to present full screen content with error \(error.localizedDescription).") } func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Ad did dismiss full screen content.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; GADRequest *request = [GADRequest request]; [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/44118910" request:request completionHandler:^(GADInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]) return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; } - (void)adDidPresentFullScreenContent:(id)ad { NSLog(@"Ad did present full screen content."); } - (void)ad:(id )ad didFailToPresentFullScreenContentWithError:(NSError *)error { NSLog(@"Ad failed to present full screen content with error %@.", [error localizedDescription]); } - (void)adDidDismissFullScreenContent:(id )ad { NSLog(@"Ad did dismiss full screen content."); }
已奖励
加载广告
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADRewardedAdDelegate { /// The rewarded ad. var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd.delegate = self rewardedAd?.load(GADRequest()) { error in if let error = error { print("Rewarded ad failed to load with error: \(error.localizedDescription)") } else { print("Rewarded ad loaded.") } } } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.rewardedAd = [[GADRewardedAd alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"]; self.rewardedAd.delegate = self; GADRequest *request = [GADRequest request]; [self.rewardedAd loadRequest:request completionHandler:^(GADRequestError * _Nullable error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); } else { NSLog(@"Rewarded ad loaded."); } }]; }
v8
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADFullScreenContentDelegate { /// The rewarded ad. var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() let request = GADRequest() GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136", request: request, completionHandler: { (ad, error) in if let error = error { print("Rewarded ad failed to load with error: \(error.localizedDescription)") return } self.rewardedAd = ad self.rewardedAd?.fullScreenContentDelegate = self } ) } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GADRequest *request = [GADRequest request]; [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; NSLog(@"Rewarded ad loaded."); self.rewardedAd.fullScreenContentDelegate = self; }
展示广告和处理奖励
激励广告要求您在用户获得奖励时处理该事件。使用 GADRewardedAd
API 版本 7 时,您可以实现 rewardedAd:userDidEarnReward:
作为 GADRewardedAdDelegate
协议的一部分。对于版本 8,您需要实现 GADUserDidEarnRewardHandler
才能展示广告。
v7
Swift
func showRewardedAd() { ... if rewardedAd.isReady { rewardedAd.present(fromRootViewController: self delegate:self) } else { print("Ad wasn't ready") } } /// Tells the delegate that the user earned a reward. func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarnReward: GADAdReward) { // TODO: Reward the user. }
Objective-C
- (void)showRewardedAd: { ... if (self.rewardedAd.isReady) { [self.rewardedAd presentFromRootViewController:self delegate:self]; } else { NSLog(@"Ad wasn't ready"); } } /// Tells the delegate that the user earned a reward. - (void)rewardedAd:(GADRewardedAd *)rewardedAd userDidEarnReward:(GADAdReward *)reward { // TODO: Reward the user. }
v8
Swift
func showRewardedAd() { ... if let ad = rewardedAd { ad.present(fromRootViewController: self, userDidEarnRewardHandler: { let reward = ad.adReward // TODO: Reward the user. } ) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showRewardedAd: { ... if (self.rewardedAd) { [self.rewardedAd presentFromRootViewController:self userDidEarnRewardHandler:^ { GADAdReward *reward = self.rewardedAd.adReward; // TODO: Reward the user. }]; } else { NSLog(@"Ad wasn't ready"); } }
展示广告事件
借助 GADRewardedAd
API,您可以将 GADRewardedAdDelegate
传递给展示广告的方法。借助 GADRewardedAd
API,您可以在展示广告之前将 GADFullscreenContentDelegate
设为广告中的一个属性。
v7
Swift
func showRewardedAd() { ... if rewardedAd.isReady { rewardedAd.present(fromRootViewController: self delegate:self) } else { print("Ad wasn't ready") } } /// Tells the delegate that the rewarded ad was presented. func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) { print("Rewarded ad failed to present with error: \(error.localizedDescription).") }
Objective-C
- (void)showRewardedAd: { ... if (self.rewardedAd.isReady) { [self.rewardedAd presentFromRootViewController:self delegate:self]; } else { NSLog(@"Ad wasn't ready"); } } /// Tells the delegate that the rewarded ad was presented. - (void)rewardedAdDidPresent:(GADRewardedAd *)rewardedAd { NSLog(@"Rewarded ad presented."); } /// Tells the delegate that the rewarded ad failed to present. - (void)rewardedAd:(GADRewardedAd *)rewardedAd didFailToPresentWithError:(NSError *)error { NSLog(@"Rewarded ad failed to present with error: %@", [error localizedDescription]); } /// Tells the delegate that the rewarded ad was dismissed. - (void)rewardedAdDidDismiss:(GADRewardedAd *)rewardedAd { NSLog(@"Rewarded ad dismissed."); }
v8
Swift
override func viewDidLoad() { super.viewDidLoad() let request = GADRequest() GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136", request: request, completionHandler: { (ad, error) in if let error = error { print(error.localizedDescription) return } self.rewardedAd = ad self.rewardedAd?.fullScreenContentDelegate = self } ) } /// Tells the delegate that the rewarded ad was presented. func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) { print("Rewarded ad failed to present with error: \(error.localizedDescription).") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; GADRequest *request = [GADRequest request]; [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; NSLog(@"Rewarded ad loaded."); self.rewardedAd.fullScreenContentDelegate = self; } /// Tells the delegate that the rewarded ad was presented. - (void)adDidPresentFullScreenContent:(id)ad { NSLog(@"Rewarded ad presented."); } /// Tells the delegate that the rewarded ad failed to present. - (void)ad:(id )ad didFailToPresentFullScreenContentWithError:(NSError *)error { NSLog(@"Rewarded ad failed to present with error: %@", [error localizedDescription]); } /// Tells the delegate that the rewarded ad was dismissed. - (void)adDidDismissFullScreenContent:(id )ad { NSLog(@"Rewarded ad dismissed."); }
移除旧版 GADRewardedBasedVideoAd API
较新的 GADRewardedAd
API 于 2019 年 3 月首次推出,18 个月多以来一直是首选奖励 API。与旧版 GADRewardedBasedVideoAd
API 相比,该 API 的功能更加强大,包括能够一次加载多个激励广告。
旧版 GADRewardedBasedVideoAd
API 在 SDK 版本 8.0.0 中已移除。
弃用智能横幅广告,改为使用自适应横幅广告
智能横幅广告已废弃,取而代之的是自适应横幅广告。自适应横幅广告的效果更好,可以让您更灵活地设置广告宽度。如果您希望继续使用全宽横幅广告,仍然可以使用自适应横幅广告完成,如以下代码段所示:
Swift
class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // Note: The safe area is not known until viewWillAppear. let adSize = getFullWidthAdaptiveAdSize() } func getFullWidthAdaptiveAdSize() -> GADAdSize { // Here safe area is taken into account, hence the view frame is used after the // view has been laid out. let frame = { () -> CGRect in if #available(iOS 11.0, *) { return view.frame.inset(by: view.safeAreaInsets) } else { return view.frame } }() return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width) } }
Objective-C
@implementation ViewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Note: The safe area is not known until viewWillAppear. GADAdSize adSize = [self getFullWidthAdaptiveAdSize]; } - (GADAdSize)getFullWidthAdaptiveAdSize { CGRect frame = self.view.frame; // Here safe area is taken into account, hence the view frame is used after // the view has been laid out. if (@available(iOS 11.0, *)) { frame = UIEdgeInsetsInsetRect(self.view.frame, self.view.safeAreaInsets); } return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width); } @end
移除应用回调
移除了所有广告格式的 willLeaveApplication
回调函数,改为使用 applicationDidEnterBackground:
和 sceneDidEnterBackground:
方法。使用操作系统级 API 时,用户每次离开您的应用时,系统都会发出通知,无论通知是否涉及广告互动。
请注意, willLeaveApplication
回调函数从来不会用作广告点击处理程序,而依赖此回调函数来报告点击并不会产生准确的指标。例如,用户点击“广告选择”图标时会启动外部浏览器,这时系统会调用该回调函数,但不会将其计为一次点击。
重命名类
下表列出了版本 8 中已更改或移除的特定类名称。步骤简述:
- 与
GADUnifiedNativeAd
相关的所有类均已重命名为GADNativeAd
。 - 移除了
GADRewardBasedVideoAd
、GADNativeExpressAdView
和GADInstreamAd
。 - 所有带
DFP
前缀的类均已替换为GAM
前缀。
v7.68.0 类 | v8.0.0 中的类 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerView 选项 | GAMBannerViewOptions |
DFP 插页式广告 | GAM 插页式广告 |
DFPRequest | GAMRequest |
GADRequestError | NSError |
GADUnifiedNativeAdView | GADNativeAdView |
GADUnifiedNativeAd | GADNativeAd |
GADUnifiedNativeAdAssetIdentifiers | GADNativeAdAssetIdentifiers |
GADUnifiedNativeAdDelegate | GADNativeAdDelegate |
GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
GADNativeCustomTemplateAd | GADCustomNativeAd |
GADNativeCustomTemplateAdLoaderDelegate | GADCustomNativeAdLoaderDelegate |
GADNativeAdDelegate | GADCustomNativeAdDelegate |
GADInAppPurchase | 已移除 |
GAD 插页式广告素材 | GAD 插页式广告 |
GADNativeExpressAdView | 已移除 |
基于 GADReward 基于的视频广告 | 已移除 |
GADInstreamAd | 已移除 |
GADInstreamAdView | 已移除 |
移除/替换的方法
下表列出了版本 8 中的具体更改。步骤简述:
- 移除了之前已废弃的方法和属性。
- 移除了所有格式的
-willLeaveApplication:
委托方法。 - 该广告联盟的类名称已移至
GADResponseInfo
属性。 - 测试设备标识符已移至
GADRequestConfiguration
属性。
v7.68.0 类 | v7.68.0 中的 API | v8.0.0 中的 API | 备注 |
---|---|---|---|
GADMobileAds | +configureWithApplicationID: | -startWithCompletionHandler: | 现在,在 Info.plist 中设置应用 ID。 |
+disableAutomaticInApp |
-disableAutomaticInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
testDeviceIdentifiers 属性适用于所有广告请求,而旧的 testDevices 属性是按请求设置的。 |
性别 | 已移除 | ||
生日 | 已移除 | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
已移除 | ||
-setLocationWithDescription: | -setLocationWith |
||
-tagForChildDirectedTreatment: | [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment] | ||
GADErrorCode | kGADError* | GADError* | 所有错误代码常量都会省略 k 前缀。 |
GADBannerView | hasAutoRefreshed | autoloadEnabled | |
inAppPurchaseDelegate | 已移除 | ||
mediatedAdView | 已移除 | ||
adNetworkClassName | responseInfo |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerView 选项 | -adSizeDelegate | 已移除 | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillLeaveApplication: | 已移除 | ||
GADNativeCustomTemplateAd | 模板 ID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
PreferredImageOrientation | GADNativeAdMediaAdOptions |
|
GAD 插页式广告素材 | inAppPurchaseDelegate | 已移除 | |
isReady | 已移除 | 请改用 canPresentFrom |
|
已使用 | 已移除 | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | responseInfo |
||
-interstitialWill |
已移除 | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |