이 페이지에서는 현재 및 이전 버전의 이전에 대해 설명합니다.
10에서 v11로 이전
部署目标下限
最低部署目标已提高至 iOS 12。
最低 Xcode 版本
支持的最低 Xcode 版本已提高至 15.1。
广告停止在 iOS 12 设备上投放
Google 移动广告 SDK 版本 11.0.0 仅在搭载 iOS 13 及更高版本的设备上投放广告。
移除了 GoogleAppMeasurement 依赖项
在版本 11.0.0 中,移除了对 GoogleAppMeasurement
的依赖。这个为 AdMob 中用户指标切换开关提供支持的依赖项将于 2024 年初停用。如需继续在 AdMob 中收集用户指标,请将您的 AdMob 应用关联到 Firebase,并将 Google Analytics for Firebase SDK 集成到您的应用中。
全屏广告展示方式的变化
以下变更会影响各种广告格式:
- 开屏广告
- 插页式广告
- 已奖励
- 插页式激励广告
-canPresentFromRootViewController:error:
和 -presentFromRootViewController:
中的视图控制器参数可为 null。如果传递 nil,则广告会从视图控制器层次结构中的最顶层视图控制器展示。
移除的方法
系统会移除以下方法。
v11.0.0 类型 | 方法 | 备注 |
---|---|---|
GADAppOpenAd | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) |
请改用 load(withAdUnitID adUnitID: String, request: GADRequest?) 。 |
GADMediationBannerAdEventDelegate | willBackgroundApplication() |
无替代项。 |
GADMediationInterstitialAdEventDelegate | willBackgroundApplication() |
无替代项。 |
GADMediationNativeAdEventDelegate | willBackgroundApplication() |
无替代项。 |
GADMediationRewardedAdEventDelegate | didRewardUser(with reward: GADAdReward) |
请改用 didRewardUser() 。 |
GADMediatedUnifiedNativeAdNotificationSource | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) |
无替代项。 |
GADRequestConfiguration | setSameAppKeyEnabled(_ enabled: Bool) |
请改用 setPublisherFirstPartyIDEnabled(_ enabled: Bool) 。 |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) |
请改用 tagForUnderAgeOfConsent 属性。 |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
请改用 tagForChildDirectedTreatment 属性。 |
已移除的属性
已移除以下属性。
v11.0.0 中的类 | 媒体资源 | 备注 |
---|---|---|
GADMediationAdConfiguration | hasUserLocation | 无替代项。 |
userLatitude | ||
userLongitude | ||
userLocationAccuracyInMeters | ||
childDirectedTreatment | 请改用 GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment 。 |
|
GADResponseInfo | adNetworkClassName | 请改用 loadedAdNetworkResponseInfo 中的 adNetworkClassName 。 |
移除了 GADAdFormatUnknown
移除了 GADAdFormatUnknown
,且无替代项。
日志记录 SDK 版本的更改
11.0.0 版移除了 sdkVersion
。如需记录 Google 移动广告 SDK 版本,请改用 versionNumber
。
版本 10.0.0
GADMobileAds.sharedInstance().sdkVersion
版本 11.0.0
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
对 GADAdLoader 错误处理方式的更改
从 11.0.0 版开始,如果 GADAdLoader
的 delegate
不符合所请求广告类型的委托协议,则不会发出广告请求。之前,该调用在发出广告请求后就会失败。
测试行为变更
请参阅表格,了解以下属性何时返回 true
的更新条件。
类 | 媒体资源 |
---|---|
GADMediationAdConfiguration | isTestRequest |
GADCustomEventRequest | isTesting |
v10.0.0 | v11.0.0 |
|
|
v9에서 v10으로 이전
广告停止在 iOS 11 设备上投放
Google 移动广告 SDK 版本 10.0.0 仅在搭载 iOS 12 及更高版本的设备上投放广告。
升级到 Google 移动广告 SDK 版本 10.0.0 不会影响您的应用在 iOS 11 和 iOS 10 设备上的行为,但广告不会在这些设备上投放。
需要 Ad Manager 应用 ID
现在,所有 Ad Manager 应用的 Info.plist
中都需要 Ad Manager 应用 ID,并且该 ID 需要采用 ca-app-pub-################~##########
格式。如需了解详情,请参阅更新您的 Info.plist。
需要 GoogleAppMeasurement.xcframework
现在,所有 Ad Manager 应用都需要 GoogleAppMeasurement.xcframework。如果您通过 CocoaPods 或 Swift Package Manager 安装 Google 移动广告 SDK,则无需执行任何其他操作。如果您手动安装框架,请参阅手动下载,了解更多详情。
不再支持使用位码构建
现在,您必须在移动应用中停用位码,才能集成 Google 移动广告 SDK。
已移除的类型
类型 | 备注 |
---|---|
GADGender | 无替代项。 |
GADMRewardBasedVideoAdNetworkAdapterProtocol | 选择广告联盟一文中列出的所有激励广告中介适配器已停止使用这些协议超过一年了。将 GADMediationAdapter 用于中介和自定义事件。 |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
已移除的属性
以下属性已移除且无替代项。
v10.0.0 中的类 | 媒体资源 |
---|---|
GADMediationAdRequest | userBirthday |
userGender | |
userHasLocation | |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription | |
GADCustomEventRequest | userHasLocation |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription |
v8에서 v9로 이전
广告停止在 iOS 10 设备上投放
Google 移动广告 SDK 版本 9.0.0 支持的最低 iOS 版本是 iOS 11。
升级到 Google 移动广告 SDK 版本 9.0.0 不会影响您的应用在 iOS 10 设备上的行为,但广告不会在这些设备上投放。
状态栏控制规定的执行更严格
从版本 9.0.0 开始,当您展示全屏格式的广告时,您的应用应确保广告能够控制状态栏的显示。如果您未能这样做,将会在日志中看到一条错误消息。
根据应用中视图控制器的具体布局,您可能无需做出任何更改即可确保实现这一点。考虑您是否需要在广告的 rootViewController
上设置 childViewControllerForStatusBarHidden
属性。
将 adDidPresentFullScreenContent: 重命名为 adWillPresentFullScreenContent:
行为无变化。委托方法在广告即将展示之前调用,因此新的方法名称可以更好地体现其功能。
移除了 GADRequest 上的 Location Settings API
- (void)setLocationWithLatitude:longitude:accuracy:
已从 GADRequest
中删除,因为 Google 不使用位置数据来定位广告。如果需要,请使用第三方 API 向第三方广告联盟提供该信息。
弃用了自定义事件接口
借助自定义事件,使用 Ad Manager 中介的发布商可以为支持的广告联盟以外的广告联盟添加广告瀑布流中介。
所有自定义事件协议均已弃用。请改用现有的 GADMediationAdapter
和 GADMediationAdEventDelegate
协议来实现相同的功能。这项变更让表达更加清晰明确,还可让您为之前不可用的激励广告和插页式滚显广告创建自定义事件。
API
下表列出了从版本 9.0.0 开始应使用的 Custom Events API 所对应的 Mediation Adapter API。
v8 | v9 | |
---|---|---|
GADCustomEventBanner GADCustomEventInterstitial GADCustomEventNativeAd |
GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediationRewardedAd GADMediationNativeAd |
delegate
|
委托由 GADMediationAdapter 类的每个加载函数的加载完成处理程序返回
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
不适用 | -loadInterscrollerAdFor |
|
不适用 | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
委托方法
下表列出了从版本 9.0.0 开始应使用的自定义事件委托方法所对应的中介广告事件委托方法。
v8 | v9 | |
---|---|---|
GADCustomEventBannerDelegate GADCustomEventInterstitialDelegate GADCustomEventNativeAdDelegate |
GADMediationAdEventDelegate | GADMediationAd |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd:
|
广告加载状态包含在 GADMediationAdapter 类中每个加载函数的加载完成处理程序中
|
|
-customEventBanner:didFailAd: -customEventInterstitial:didFailAd:
|
||
-customEventBannerWasClicked: -customEventInterstitialWasClicked:
|
-reportClick |
|
-customEventBannerWill -customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid -customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
其他已移除/替换的方法和常量
对方法、常量或属性的变更 | |
---|---|
带 kGAD- 前缀的常量
|
已移除。使用带 GAD- 前缀的常量。
|
GADAdNetworkResponseInfo
|
移除了 credentials 。请改用 adUnitMapping 。
|
GAMRequest
|
废弃了 GAMRequest 中的 kGAMSimulatorID 。请在 GADRequestConfiguration 中改用 GADSimulatorID 。
|
GADCustomNativeAd
|
废弃了 GADCustomNativeAd 中的 mediaView 。请改用 mediaContent 。
|
GoogleMobileAds 中的 In-App Purchase API |
移除了 GoogleMobileAds 中的 inAppPurchase API。 |
v7에서 v8로 이전
Google 모바일 광고 SDK 버전 8.0.0에는 몇 가지 주요 변경사항이 있으며 일부 API가 삭제되거나 이름이 변경됩니다.
전체 화면 형식 API 업데이트
버전 8.0.0부터 전면 광고와 보상형 광고는 일관성을 높이기 위해 일반적인 전체 화면 광고 스타일을 공유합니다. 새로운 전체 화면 광고 API는 버전 7 전체 화면 광고 API와 크게 두 가지 차이점이 있습니다.
정적 클래스 메서드
load
앞서 살펴본 전체 화면 광고를 로드/게재하는 방법은 다음과 같습니다.
- 광고 객체 인스턴스를 만들고 이에 대한 참조를 보유합니다.
- 로드를 처리하고 콜백을 표시하는 대리자를 할당합니다.
- 광고를 로드합니다.
isReady
를 사용하여 광고가 로드되었는지 확인합니다.- 광고를 게재합니다.
버전 8에서는 접근 방식이 약간 변경됩니다. 로드 콜백이 더 이상 대리자의 일부가 아닙니다. 대신
load
메서드에 완료 핸들러로 전달됩니다.- 광고 클래스의 정적 로드 메서드를 호출하고 로드 완료 핸들러를 제공합니다.
- 로드 완료 콜백에서 반환되어 로드된 광고에 대한 참조를 유지합니다.
- 콜백 표시를 처리하는 대리자를 할당합니다.
- 광고를 게재합니다.
새로운 접근 방식에는 다음과 같은 이점이 있습니다.
- 로드되지 않은 광고에 대한 참조가 없습니다.
- 로드되는 동안 광고 객체를 유지하지 않아도 됩니다.
일관된 광고 이벤트.
이벤트 유형 기존 API 버전 8 API 로드 이벤트 GADInterstitialDelegate
또는GADRewardedAdDelegate
GAMInterstitialAdLoadCompletionHandler
또는GADRewardedAdLoadCompletionHandler
프레젠테이션 이벤트 GADFullScreenContentDelegate
이전에는 광고 이벤트를 수신 대기하려면
GADInterstitialDelegate
프로토콜을 전면 광고의 대리자 속성에 구현하는 클래스를 등록하거나 사용 중인 형식에 따라GADRewardedAdDelegate
프로토콜을 보상형 광고의 대리자 속성에 구현하는 클래스를 등록했습니다. 동일한 대리자에는 광고의 로드 및 프레젠테이션 수명 주기와 관련된 메서드가 있었습니다.버전 8에서는 로드 이벤트와 프레젠테이션 이벤트가 별개입니다. 이제 광고를 로드하기 전에 단일 대리자를 설정할 필요 없이 광고를 게재하기 전에 언제든지
GADFullScreenContentDelegate
를 등록할 수 있습니다. 각 형식과 관련된 광고 로드 이벤트는 로드 메서드에 전달된 단일 로드 완료 핸들러로 이동합니다.
전면 광고
광고 로드
아래의 코드 스니펫은 전면 광고를 로드하고 광고 로드에 성공하거나 실패할 때 이벤트를 수신 대기하는 방법을 보여줍니다.
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: DFPInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/6499/example/interstitial") interstitial.delegate = self let request = GAMRequest() interstitial.load(request) } /// Tells the delegate an ad request succeeded. func interstitialDidReceiveAd(_ ad: DFPInterstitial) { print("Interstitial ad loaded.") } /// Tells the delegate an ad request failed. func interstitial(_ ad: DFPInterstitial, didFailToReceiveAdWithError error: GADRequestError) { print("Interstitial ad failed to load with error: \(error.localizedDescription)") } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) DFPInterstitial *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:@"/6499/example/interstitial"]; self.interstitial.delegate = self; GAMRequest *request = [GAMRequest request]; [self.interstitial loadRequest:request]; } /// Tells the delegate an ad request succeeded. - (void)interstitialDidReceiveAd:(DFPInterstitial *)ad { NSLog(@"Insterstitial ad loaded."); } /// Tells the delegate an ad request failed. - (void)interstitial:(DFPInterstitial *)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: GAMInterstitialAd? override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GAMInterstitialAd.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) GAMInterstitialAd *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/6499/example/interstitial" request:request completionHandler:^(GAMInterstitialAd *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 = DFPInterstitial(adUnitID: "/6499/example/interstitial") interstitial.delegate = self ... } /// Tells the delegate that an interstitial will be presented. func interstitialWillPresentScreen(_ ad: DFPInterstitial) { print("Interstitial ad will be presented.") } /// Tells the delegate the interstitial is to be animated off the screen. func interstitialWillDismissScreen(_ ad: DFPInterstitial) { print("Interstitial ad will be dismissed.") } /// Tells the delegate the interstitial had been animated off the screen. func interstitialDidDismissScreen(_ ad: DFPInterstitial) { 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: DFPInterstitial) { print("Interstitial ad will leave application.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:"/6499/example/interstitial"]; self.interstitial.delegate = self; ... } /// Tells the delegate that an interstitial will be presented. - (void)interstitialWillPresentScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will be presented."); } /// Tells the delegate the interstitial is to be animated off the screen. - (void)interstitialWillDismissScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will be dismissed."); } /// Tells the delegate the interstitial had been animated off the screen. - (void)interstitialDidDismissScreen:(DFPInterstitial *)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:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will leave application."); }
v8
Swift
override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GAMInterstitialAd.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]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/6499/example/interstitial" request:request completionHandler:^(GAMInterstitialAd *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(GAMRequest()) { 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; GAMRequest *request = [GAMRequest 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 = GAMRequest() 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]; GAMRequest *request = [GAMRequest 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 = GAMRequest() 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]; GAMRequest *request = [GAMRequest 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에 비해 더 많은 개선사항이 적용되었습니다.
SDK 버전 8.0.0에서 기존 GADRewardedBasedVideoAd
API가 삭제되었습니다.
스마트 배너 지원 중단 대신 적응형 배너로 대체
스마트 배너 광고의 지원이 중단되고 적응형 배너 광고로 대체됩니다. 적응형 배너를 사용하면 우수한 실적과 광고 너비를 더 유연하게 설정할 수 있습니다. 전체 너비 배너를 계속 사용하려는 경우 다음 코드 스니펫과 같이 적응형 배너를 사용하면 됩니다.
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에서 변경되었거나 삭제된 특정 클래스 이름이 나열되어 있습니다. 요약:
GADUnifiedNativeAd
와 관련된 모든 클래스의 이름이GADNativeAd
로 변경되었습니다.GADRewardBasedVideoAd
,GADNativeExpressAdView
,GADInstreamAd
가 삭제되었습니다.DFP
접두사가 있는 모든 클래스를GAM
접두사로 대체했습니다.
v7.68.0 클래스 | v8.0.0 클래스 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerViewOptions | GAMBannerViewOptions |
DFPInterstitial | GAM 전면 광고 |
DFPRequest | GAMRequest |
GADRequestError | NSError |
GADUnifiedNativeAdView | GADNativeAdView |
GADUnifiedNativeAd | GADNativeAd |
GADUnifiedNativeAdAssetIdentifiers | GADNativeAdAssetIdentifiers |
GADUnifiedNativeAdDelegate | GADNativeAdDelegate |
GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
GADNative맞춤 템플릿 광고 | GADCustomNativeAd |
GADNativeCustomTemplateAdLoaderDelegate | GADCustomNativeAdLoaderDelegate |
GADNativeAdDelegate | GADCustomNativeAdDelegate |
GADInAppPurchase | 삭제됨 |
GADInterstitial | GAD전면 광고 |
GADNativeExpressAdView | 삭제됨 |
GADRewardBasedVideoAd | 삭제됨 |
GAD인스트림 광고 | 삭제됨 |
GADInstreamAdView | 삭제됨 |
삭제/대체된 메서드
아래 표에는 버전 8의 구체적인 변경사항이 나와 있습니다. 요약:
- 이전에 지원 중단된 메서드 및 속성이 삭제되었습니다.
- 모든 형식에서
-willLeaveApplication:
위임 메서드가 삭제되었습니다. - 광고 네트워크 클래스 이름이
GADResponseInfo
속성으로 이동되었습니다. - 테스트 기기 식별자가
GADRequestConfiguration
속성으로 이동했습니다.
v7.68.0 클래스 | v7.68.0 API | API 버전 8.0.0 | Notes |
---|---|---|---|
GADMobile 광고 | +configureWithApplicationID를 사용합니다. | -startWithcompleteHandler: | 이제 앱 ID가 Info.plist에 설정됩니다. |
+disableAutomatedInApp |
-disableAutomatedInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
이전 testDevices 속성은 요청별로 설정되었지만, testDeviceIdentifiers 속성은 모든 광고 요청에 적용됩니다. |
gender | 삭제됨 | ||
생일 | 삭제됨 | ||
+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: | |
DFPBannerViewOptions | -adSizeDelegate | 삭제됨 | |
GADBannerViewDelegate | -adViewDidReceivedAd: | -bannerViewDidReceivedAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillLeaveApplication: | 삭제됨 | ||
GADNative맞춤 템플릿 광고 | 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 |