本頁面說明 iOS 版 Google Mobile Ads SDK 目前和舊版的遷移作業。11.0.0 版預計於 2024 年 1 月發布。
從 SDK 版本 v10 遷移至 v11
Minimum deployment target
The minimum deployment target has been increased to iOS 12.
Minimum Xcode version
The minimum supported Xcode version has been increased to 15.1.
Ads stop serving on iOS 12
Google Mobile Ads SDK version 11.0.0 serves ads only on devices running iOS 13 and higher.
Removed GoogleAppMeasurement dependency
In version 11.0.0, the dependency on
GoogleAppMeasurement
has been
removed. This dependency that powered the user metrics toggle in AdMob will be
discontinued in early 2024. To
continue collecting user metrics in AdMob,
link your AdMob app to Firebase and
integrate the
Google Analytics for Firebase SDK into
your app.
Changes to full-screen ad presentation
The following changes affect the various ad formats:
- App open
- Interstitial
- Rewarded
- Rewarded interstitial
The view controller parameter in -canPresentFromRootViewController:error:
and
-presentFromRootViewController:
is nullable. If nil is passed, the ad is
presented from the topmost view controller in the view controller hierarchy.
Methods removed
The following methods are removed.
v11.0.0 Type | Method | Notes |
---|---|---|
GADAppOpenAd | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) |
Use load(withAdUnitID adUnitID: String, request: GADRequest?) instead. |
GADMediationBannerAdEventDelegate | willBackgroundApplication() |
No replacement. |
GADMediationInterstitialAdEventDelegate | willBackgroundApplication() |
No replacement. |
GADMediationNativeAdEventDelegate | willBackgroundApplication() |
No replacement. |
GADMediationRewardedAdEventDelegate | didRewardUser(with reward: GADAdReward) |
Use didRewardUser() instead. |
GADMediatedUnifiedNativeAdNotificationSource | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) |
No replacement. |
GADRequestConfiguration | setSameAppKeyEnabled(_ enabled: Bool) |
Use setPublisherFirstPartyIDEnabled(_ enabled: Bool) instead. |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) |
Use the tagForUnderAgeOfConsent property instead. |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
Use the tagForChildDirectedTreatment property instead. |
Properties removed
The following properties are removed.
v11.0.0 Class | Property | Notes |
---|---|---|
GADMediationAdConfiguration | hasUserLocation | No replacement. |
userLatitude | ||
userLongitude | ||
userLocationAccuracyInMeters | ||
childDirectedTreatment | Use GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment instead. |
|
GADResponseInfo | adNetworkClassName | Use adNetworkClassName from loadedAdNetworkResponseInfo instead. |
Removed GADAdFormatUnknown
Removed GADAdFormatUnknown
with no replacement.
Changes to logging SDK version
Version 11.0.0 removes sdkVersion
. To log the Google Mobile Ads SDK version,
use versionNumber
instead.
Version 10.0.0
GADMobileAds.sharedInstance().sdkVersion
Version 11.0.0
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
Changes to GADAdLoader error handling
Starting in version 11.0.0, GADAdLoader
doesn't make an ad request if its
delegate
doesn't conform to the requested ad types' delegate protocol. Previously, it
failed after the ad request was made.
Changes to testing behavior
See the table which shows the updated conditions for when the following
properties return true
.
Class | Property |
---|---|
GADMediationAdConfiguration | isTestRequest |
GADCustomEventRequest | isTesting |
v10.0.0 | v11.0.0 |
|
|
從 v9 遷移至 v10
廣告會在 iOS 11 上停止放送
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 | 無法更換。 |
GADMRewardBasedVideoAdNetworkAdapterProtocol | 「 選擇聯播網」中列出的所有獎勵中介服務轉接程式均已在一年內停止使用這些通訊協定。使用 GADMediationAdapter 處理中介服務和自訂事件。 |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
已移除資源
下列屬性已移除,且不會替換。
v10.0.0 類別 | 屬性 |
---|---|
GADMediationAdRequest | userBirthday |
userGender | |
userHasLocation | |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription | |
GADCustomEventRequest | userHasLocation |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription |
從 v8 遷移至 v9
Ads stop serving on iOS 10
The minimum iOS version the Google Mobile Ads SDK version 9.0.0 supports is iOS 11.
Upgrading to Google Mobile Ads SDK version 9.0.0 will not break your app on iOS 10 devices, however, no ads will be served on those devices.
Stricter enforcement of status bar controls
Starting from version 9.0.0, when you present full-screen format ads, your app should ensure that the ads are able to control the presentation of the status bar. You will see an error message in the logs if you fail to do so.
Depending on the specific layout of view controllers in your app, you might not
need to make any changes to ensure this. Consider whether you need to set the
childViewControllerForStatusBarHidden
property on your ad's rootViewController
.
Rename adDidPresentFullScreenContent: to adWillPresentFullScreenContent:
There is no behavior change. The delegate method is invoked right before the ad is about to be presented, so the new method name better reflects its functionality.
Remove location setting API on GADRequest
- (void)setLocationWithLatitude:longitude:accuracy:
has been deleted from
GADRequest
since location data is not used by Google to target ads. Use
third-party APIs to provide the information to third-party ad networks if
required.
Custom event interfaces deprecation
Custom events enable publishers using AdMob Mediation to add waterfall mediation for an ad network that isn't one of the supported ad networks.
All the custom event protocols are deprecated. Instead, use the existing
GADMediationAdapter
and
GADMediationAdEventDelegate
protocols to achieve the same functionalities. This change improves clarity and
enables you to create custom events for rewarded ads and interscroller ads which
were not previously available.
APIs
The table below lists the corresponding mediation adapter APIs to custom events APIs that should be used starting from version 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBanner GADCustomEventInterstitial GADCustomEventNativeAd |
GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediationRewardedAd GADMediationNativeAd |
delegate
|
Delegate is returned by the load completion handler of each load function
of GADMediationAdapter class
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
N/A | -loadInterscrollerAdFor |
|
N/A | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
Delegate methods
The table below lists the corresponding mediation ad event delegate methods to custom event delegate methods that should be used starting from version 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBannerDelegate GADCustomEventInterstitialDelegate GADCustomEventNativeAdDelegate |
GADMediationAdEventDelegate | GADMediationAd |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd:
|
Ad load status is included in the load completion handler of
each load function in the GADMediationAdapter class
|
|
-customEventBanner:didFailAd: -customEventInterstitial:didFailAd:
|
||
-customEventBannerWasClicked: -customEventInterstitialWasClicked:
|
-reportClick |
|
-customEventBannerWill -customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid -customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
Other removed/replaced methods and constants
Changes to method, constant, or property | |
---|---|
kGAD- prefixed constants
|
Removed. Use GAD- prefixed constants.
|
GADAdNetworkResponseInfo
|
credentials were removed. Use adUnitMapping
instead.
|
GADCustomNativeAd
|
mediaView in GADCustomNativeAd is deprecated.
Use mediaContent instead.
|
In-App Purchase APIs in GoogleMobileAds |
inAppPurchase APIs in GoogleMobileAds were
removed.
|
從 v7 遷移至 v8
Google Mobile Ads SDK 8.0.0 版推出了幾項重大異動, 部分 API 重新命名和移除
全螢幕格式 API 更新
自 8.0.0 版起,插頁式廣告和獎勵廣告將共用通用 讓廣告樣式更一致這些全新的全螢幕廣告 API 有兩個 與第 7 版全螢幕廣告 API 的差別:
靜態類別方法
load
。先前的載入/顯示全螢幕廣告的方法如下:
- 建立廣告物件例項並保留其參照。
- 指派負責處理負載及顯示回呼的委派。
- 載入廣告。
- 使用
isReady
檢查廣告是否已載入。 - 放送廣告。
在第 8 版中,做法略有不同。載入回呼 委派代表。而是會做為
load
方法的 完成處理常式:- 呼叫廣告類別上的靜態載入方法,並提供載入完成 處理常式。
- 在載入完成回呼中,保留所載入廣告的參照 。
- 指派代表處理顯示回呼的委派。
- 放送廣告。
新做法有以下優點:
- 您不會有廣告未載入的參照。
- 您不需要在廣告物件載入期間按住該物件。
一致的廣告事件:
事件類型 現有 API 第 8 版 API 載入事件 GADInterstitialDelegate
或GADRewardedAdDelegate
GADInterstitialAdLoadCompletionHandler
或GADRewardedAdLoadCompletionHandler
簡報活動 GADFullScreenContentDelegate
先前,要監聽任何廣告事件,您需要註冊一個類別 會實作
GADInterstitialDelegate
敬上 指向插頁式廣告委派屬性的通訊協定,或是註冊一個 會實作GADRewardedAdDelegate
。 指向獎勵廣告委派屬性的通訊協定 (視哪種格式而定) 您使用的資源同一委派項目具有與載入和載入作業相關的方法 廣告的生命週期在第 8 版中,載入事件和顯示事件會分開計算。您現在可以 註冊
GADFullScreenContentDelegate
敬上 完全不必設定一個 。每個專屬的廣告載入事件 格式,請移至載入方法中傳遞的單一載入完成處理常式。
插頁式
載入廣告
下方程式碼片段說明如何載入插頁式廣告,並監聽 事件。
第 7 版
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: GADInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") 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/4411468910"]; 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/4411468910" 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; }]; }
多媒體廣告
第 7 版
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"); } }
簡報廣告事件
以下程式碼片段說明如何處理廣告出現時的回呼 表示 (成功或失敗) 以及關閉時。
第 7 版
Swift
override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") 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/4411468910"]; 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/4411468910" 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."); }
已獲得獎勵
載入廣告
第 7 版
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
,才能
而非放送該廣告
第 7 版
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
做為廣告的屬性,才能
廣告。
第 7 版
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."); }
移除舊版 GAD 獎勵 VideoAd API
更新
GADRewardedAd
敬上
API 是在 2019 年 3 月首次推出,也是使用者首選的獎勵廣告
擁有超過 18 個月。強化項目比舊版更多
GADRewardedBasedVideoAd
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:
方法。只要使用 OS 層級 API,無論使用者何時離開您的應用程式,
是否與廣告互動有關
請注意, willLeaveApplication
回呼並非刻意設計
廣告點擊處理常式,並仰賴此回呼回報點擊並未
以便產生準確的指標例如,按一下 AdChoices 圖示
啟動外部瀏覽器叫用回呼的圖示,但未計算
點擊。
重新命名類別
下表列出已變更或移除的特定類別名稱 8.0 版。摘要說明:
- 與「
GADUnifiedNativeAd
」相關的所有課程已重新命名為GADNativeAd
。 GADRewardBasedVideoAd
、GADNativeExpressAdView
和GADInstreamAd
有 已移除- 所有包含
DFP
前置字串的類別都已替換為GAM
前置字串。
7.68.0 版類別 | 8.0.0 版類別 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerViewOptions | GAMBannerViewOptions |
DFPInterstitial | GAMInterstitialAd |
DFPRequest | GAMRequest |
GADRequestError | NSError |
GADUnifiedNativeAdView | GADNativeAdView |
GADUnifiedNativeAd | GADNativeAd |
GADUnifiedNativeAdAssetIdentifiers | GADNativeAdAssetIdentifiers |
GADUnifiedNativeAdDelegate | GADNativeAdDelegate |
GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
GADNativeCustomTemplateAd | GADCustomNativeAd |
GADNativeCustomTemplateAdLoaderDelegate | GADCustomNativeAdLoaderDelegate |
GADNativeAdDelegate | GADCustomNativeAdDelegate |
GADInAppPurchase | 已移除 |
GADInterstitial | GADInterstitialAd |
GADNativeExpressAdView | 已移除 |
GADRewardBasedVideoAd | 已移除 |
GADInstreamAd | 已移除 |
GADInstreamAdView | 已移除 |
移除/取代的方法
下表列出了第 8 版的各項異動。摘要說明:
- 已移除先前淘汰的方法和屬性。
- 已移除所有格式的
-willLeaveApplication:
委派方法。 - 廣告聯播網類別名稱已移至
GADResponseInfo
屬性。 - 測試裝置 ID 已移至
GADRequestConfiguration
資源。
7.68.0 版類別 | 7.68.0 版 API | API 8.0.0 版 | 附註 |
---|---|---|---|
GADMobileAds | +configureWithApplicationID: | -startWithCompletionHandler: | 應用程式 ID 現在是在 Info.plist 中設定。 |
+disableAutomatedInApp |
-disableAutomatedInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
testDeviceIdentifiers 屬性適用於所有廣告請求,而 每項要求都設定舊的 testDevice 屬性。 |
性別 | 已移除 | ||
生日 | 已移除 | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
已移除 | ||
-setLocationWithDescription: | -setLocationWith |
||
-tagForChildDirectedTreatment: | [GADMobileAds.sharedInstance.requestConfiguration 標記 ForChildDirectedTreatment] | ||
GADErrorCode | kGADError* | GADError* | 系統會從所有錯誤代碼常數中捨棄 k 前置字串。
|
GADBannerView | hasAutoRefreshed | autoloadEnabled | |
inAppPurchaseDelegate | 已移除 | ||
mediatedAdView | 已移除 | ||
adNetworkClassName | responseInfo |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerViewOptions | -adSizeDelegate | 已移除 | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillLeaveApplication: | 已移除 | ||
GADNativeCustomTemplateAd | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GADNativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | 已移除 | |
isReady | 已移除 | 請改用 canPresentFrom |
|
hasBeenUsed | 已移除 | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | responseInfo |
||
-interstitialWill |
已移除 | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |