Trang này trình bày cách di chuyển đối với phiên bản hiện tại và phiên bản cũ của SDK quảng cáo trên thiết bị di động của Google dành cho iOS. Phiên bản 12.0.0 dự kiến sẽ được phát hành vào tháng 2 năm 2025.
Di chuyển từ phiên bản 11 sang phiên bản 12
Nâng cấp lên Xcode 16.0
Phiên bản Xcode tối thiểu được hỗ trợ đã tăng lên 16.0.
Hỗ trợ đặt tên Swift
Phiên bản 12.0.0 bao gồm các thay đổi để tuân theo quy ước đặt tên trong Nguyên tắc thiết kế API của Swift. Những thay đổi này chỉ ảnh hưởng đến Swift. Không có thay đổi nào về cách đặt tên đối với API Objective-C.
Thay đổi tiền tố lớp
Các thay đổi sau đây đã được thực hiện đối với tiền tố lớp:
- Xoá tiền tố
GAD
trên tên cho tất cả các loại. - Đổi tên tiền tố
GAM
thànhAdManager
. - Đổi tên tiền tố
GADM
thànhMediation
.
Giải quyết lỗi
Cách tốt nhất để giải quyết các lỗi phát sinh từ những thay đổi này là sửa lỗi bằng tính năng Sửa lỗi.
Giải quyết xung đột về tên
Để giải quyết xung đột khi đặt tên, hãy sử dụng không gian tên do mô-đun cung cấp. Ví dụ: GADRequest
hiện được đặt tên là Request
. Các không gian tên mẫu sau đây
lớp Request
của SDK quảng cáo trên thiết bị di động của Google:
import GoogleMobileAds
...
var request: GoogleMobileAds.Request?
Danh sách chi tiết về các thay đổi đối với Swift
Các bảng sau đây liệt kê những thay đổi đối với API Swift:
Phiên bản 11 | Phiên bản 12 |
---|---|
GADAdapterInitializationState |
AdapterInitializationState |
GADAdChoicesPosition |
AdChoicesPosition |
GADAdChoicesView |
AdChoicesView |
GADAdFormat |
AdFormat |
GADAdLoader |
AdLoader |
GADAdLoaderAdType |
AdLoaderAdType |
GADAdLoaderDelegate |
AdLoaderDelegate |
GADAdMetadataDelegate |
AdMetadataDelegate |
GADAdMetadataProvider |
AdMetadataProvider |
GADAdNetworkExtras |
AdNetworkExtras |
GADAdNetworkResponseInfo |
AdNetworkResponseInfo |
GADAdReward |
AdReward |
GADAdSize |
AdSize |
GADAdSizeDelegate |
AdSizeDelegate |
GADAdValue |
AdValue |
GADAdValuePrecision |
AdValuePrecision |
GADAppEventDelegate |
AppEventDelegate |
GADAppOpenAd |
AppOpenAd |
GADAppOpenSignalRequest |
AppOpenSignalRequest |
GADAudioVideoManager |
AudioVideoManager |
GADAudioVideoManagerDelegate |
AudioVideoManagerDelegate |
GADBannerSignalRequest |
BannerSignalRequest |
GADBannerView |
BannerView |
GADBannerViewDelegate |
BannerViewDelegate |
GADCustomEventExtras |
CustomEventExtras |
GADCustomEventRequest |
CustomEventRequest |
GADCustomNativeAd |
CustomNativeAd |
GADCustomNativeAdLoaderDelegate |
CustomNativeAdLoaderDelegate |
GADCustomNativeAdDelegate |
CustomNativeAdDelegate |
GADDebugOptionsViewControllerDelegate |
DebugOptionsViewControllerDelegate |
GADDebugOptionsViewController |
DebugOptionsViewController |
GADDisplayAdMeasurement |
DisplayAdMeasurement |
GADExtras |
Extras |
GADFullScreenPresentingAd |
FullScreenPresentingAd |
GADFullScreenContentDelegate |
FullScreenContentDelegate |
GADAdapterStatus |
AdapterStatus |
GADInitializationStatus |
InitializationStatus |
GADInterstitialAd |
InterstitialAd |
GADInterstitialSignalRequest |
InterstitialSignalRequest |
GADMediaAspectRatio |
MediaAspectRatio |
GADMediaContent |
MediaContent |
GADMediaView |
MediaView |
GADMobileAds |
MobileAds |
GADMultipleAdsAdLoaderOptions |
MultipleAdsAdLoaderOptions |
GADMuteThisAdReason |
MuteThisAdReason |
GADNativeAd |
NativeAd |
GADNativeAdLoaderDelegate |
NativeAdLoaderDelegate |
GADNativeAdView |
NativeAdView |
GADNativeAdCustomClickGestureOptions |
NativeAdCustomClickGestureOptions |
GADNativeAdDelegate |
NativeAdDelegate |
GADNativeAdImage |
NativeAdImage |
GADNativeAdImageAdLoaderOptions |
NativeAdImageAdLoaderOptions |
GADNativeAdInlineBehavior |
NativeAdInlineBehavior |
GADNativeAdInlineBehaviorOptions |
NativeAdInlineBehaviorOptions |
GADNativeAdMediaAdLoaderOptions |
NativeAdMediaAdLoaderOptions |
GADNativeAdUnconfirmedClickDelegate |
NativeAdUnconfirmedClickDelegate |
GADNativeAdViewAdOptions |
NativeAdViewAdOptions |
GADNativeMuteThisAdLoaderOptions |
NativeMuteThisAdLoaderOptions |
GADNativeSignalRequest |
NativeSignalRequest |
GADPresentationError |
PresentationError |
GADPublisherPrivacyPersonalizationState |
PublisherPrivacyPersonalizationState |
GADQueryInfo |
QueryInfo |
GADRequest |
Request |
GADRequestError |
RequestError |
GADRequestConfiguration |
RequestConfiguration |
GADResponseInfo |
ResponseInfo |
GADRewardedAd |
RewardedAd |
GADRewardedSignalRequest |
RewardedSignalRequest |
GADRewardedInterstitialAd |
RewardedInterstitialAd |
GADRewardedInterstitialSignalRequest |
RewardedInterstitialSignalRequest |
GADSearchBannerView |
SearchBannerView |
GADServerSideVerificationOptions |
ServerSideVerificationOptions |
GADSignal |
Signal |
GADSignalRequest |
SignalRequest |
GADVersionNumber |
VersionNumber |
GADVideoController |
VideoController |
GADVideoControllerDelegate |
VideoControllerDelegate |
Ad Manager | |
GAMBannerAdLoaderDelegate |
AdManagerBannerAdLoaderDelegate |
GAMBannerView |
AdManagerBannerView |
GAMBannerViewOptions |
AdManagerBannerViewOptions |
GAMInterstitialAd |
AdManagerInterstitialAd |
GAMRequest |
AdManagerRequest |
Dàn xếp | |
GADMAdNetworkAdapter |
MediationAdNetworkAdapter |
GADMAdNetworkConnector |
MediationAdNetworkConnector |
GADMBannerAnimationType |
MediationBannerAnimationType |
GADMediatedUnifiedNativeAd |
MediationUnifiedNativeAd |
GADMediatedUnifiedNativeAdNotificationSource |
MediationUnifiedNativeAdNotificationSource |
GADMediationAd |
MediationAd |
GADMediationAdConfiguration |
MediationAdConfiguration |
GADMediationAdEventDelegate |
MediationAdEventDelegate |
GADMediationAdRequest |
MediationAdRequest |
GADMediationAdapter |
MediationAdapter |
GADMediationAppOpenAd |
MediationAppOpenAd |
GADMediationAppOpenAdEventDelegate |
MediationAppOpenAdEventDelegate |
GADMediationBannerAd |
MediationBannerAd |
GADMediationBannerAdConfiguration |
MediationBannerAdConfiguration |
GADMediationBannerAdEventDelegate |
MediationBannerAdEventDelegate |
GADMediationCredentials |
MediationCredentials |
GADMediationInterstitialAd |
MediationInterstitialAd |
GADMediationInterstitialAdConfiguration |
MediationInterstitialAdConfiguration |
GADMediationInterstitialAdEventDelegate |
MediationInterstitialAdEventDelegate |
GADMediationNativeAd |
MediationNativeAd |
GADMediationNativeAdConfiguration |
MediationNativeAdConfiguration |
GADMediationNativeAdEventDelegate |
MediationNativeAdEventDelegate |
GADMediationRewardedAd |
MediationRewardedAd |
GADMediationRewardedAdConfiguration |
MediationRewardedAdConfiguration |
GADMediationRewardedAdEventDelegate |
MediationRewardedAdEventDelegate |
GADMediationServerConfiguration |
MediationServerConfiguration |
Đặt giá thầu thời gian thực | |
GADRTBAdapter |
RTBAdapter |
GADRTBMediationSignalsConfiguration |
RTBMediationSignalsConfiguration |
GADRTBRequestParameters |
RTBRequestParameters |
Hằng số
Phiên bản 11 | Phiên bản 12 |
---|---|
GADAdLoaderAdType.gamBanner |
AdLoaderAdType.adManagerBanner |
GADAdSizeBanner |
AdSizeBanner |
GADAdSizeFluid |
AdSizeFluid |
GADAdSizeFullBanner |
AdSizeFullBanner |
GADAdSizeInvalid |
AdSizeInvalid |
GADAdSizeLargeBanner |
AdSizeLargeBanner |
GADAdSizeLeaderboard |
AdSizeLeaderboard |
GADAdSizeMediumRectangle |
AdSizeMediumRectangle |
GADAdSizeSkyscraper |
AdSizeSkyscraper |
GoogleMobileAdsVersionString |
GoogleMobileAdsVersion |
Thuộc tính
Loại | Phiên bản 11 | Phiên bản 12 |
---|---|---|
GADAdLoader | loading |
isLoading |
GADAudioVideoManager | audioSessionApplicationManaged |
isAudioSessionApplicationManaged |
GADBannerView | autoloadEnabled |
isAutoloadEnabled |
GADMobileAds | sharedInstance |
shared |
applicationMuted |
isApplicationMuted |
|
GADMuteThisAdReason | reasonDescription |
reason |
GADNativeAd | customMuteThisAdAvailable |
isCustomMuteThisAdAvailable |
GADNativeAdCustomClickGestureOptions | tapsAllowed |
areTapsAllowed |
GADNativeAdImageAdLoaderOptions | imageLoadingDisabled |
isImageLoadingDisabled |
GADNativeMuteThisAdLoaderOptions | customMuteThisAdRequested |
isCustomMuteThisAdRequested |
GADNativeSignalRequest | imageLoadingDisabled |
isImageLoadingDisabled |
customMuteThisAdRequested |
isCustomMuteThisAdRequested |
|
GADRequest | neighboringContentURLStrings |
neighboringContentURLs |
GADResponseInfo | extrasDictionary |
extras |
GADServerSideVerificationOptions | customRewardString |
customRewardText |
GADSignal | signalString |
signal |
GADSignalRequest | neighboringContentURLStrings |
neighboringContentURLs |
GADVideoController | customControlsRequested |
areCustomControlsRequested |
clickToExpandEnabled |
isClickToExpandEnabled |
|
GADVideoOptions | startMuted |
shouldStartMuted |
customControlsRequested |
areCustomControlsRequested |
|
clickToExpandRequested |
isClickToExpandRequested |
Hàm
Loại | Phiên bản 11 | Phiên bản 12 |
---|---|---|
GADAdSize | GADPortraitInlineAdaptiveBannerAdSizeWithWidth(_:) |
portraitInlineAdaptiveBanner(width:) |
GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(_:) |
landscapeInlineAdaptiveBanner(width:) |
|
GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(_:) |
currentOrientationInlineAdaptiveBanner(width:) |
|
GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(_:, _:) |
inlineAdaptiveBanner(width:maxHeight:) |
|
GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(_:) |
portraitAnchoredAdaptiveBanner(width:) |
|
GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(_:) |
landscapeAnchoredAdaptiveBanner(width:) |
|
GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(_:) |
currentOrientationAnchoredAdaptiveBanner(width:) |
|
GADAdSizeFromCGSize(_:) |
adSizeFor(cgSize:) |
|
GADAdSizeFullWidthPortraitWithHeight(_:) |
fullWidthPortrait(height:) |
|
GADAdSizeFullWidthLandscapeWithHeight(_:) |
fullWidthLandscape(height:) |
|
GADAdSizeEqualToSize(_:, _:) |
isAdSizeEqualToSize(size1:size2:) |
|
IsGADAdSizeValid(_:) |
isAdSizeValid(size:) |
|
GADAdSizeIsFluid(_:) |
isAdSizeFluid(size:) |
|
CGSizeFromGADAdSize(_:) |
cgSize(for:) |
|
NSStringFromGADAdSize(_:) |
string(for:) |
|
NSValueFromGADAdSize(_:) |
nsValue(for:) |
|
GADAdSizeFromNSValue(_:) |
adSizeFor(nsValue:) |
|
GADClosestValidSizeForAdSizes(_:_:) |
closestValidSizeForAdSizes(original:possibleAdSizes:) |
|
GADAppEventDelegate | adView(_:didReceiveAppEvent:withInfo:) |
adView(_:didReceiveAppEvent:with:) |
interstitialAd(_:didReceiveAppEvent:withInfo:) |
adView(_:didReceiveAppEvent:with:) |
|
GADAppOpenAd | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:) |
present(from:) |
|
GADBannerView | load(withAdResponseString:) |
load(with:) |
GADInterstitial | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:) |
present(from:) |
|
GADRewardedAd | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:userDidEarnRewardHandler:) |
present(from:userDidEarnRewardHandler:) |
|
GADRewardedInterstitialAd | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:userDidEarnRewardHandler:) |
present(from:userDidEarnRewardHandler:) |
|
GADVersionNumber | GADGetStringFromVersionNumber(_ version: GADVersionNumber) |
string(for:) |
Dàn xếp | ||
GADMAdNetworkAdapter | getBannerWith(_:) |
getBanner(with:) |
presentInterstitial(fromRootViewController:) |
presentInterstitial(from:) |
|
getNativeAd(withAdTypes:options:) |
getNativeAd(with:options:) |
|
GADMediatedUnifiedNativeAd | didRecordClickOnAsset(withName:view:viewController:) |
didRecordClickOnAsset(with:view:viewController:) |
GADMediationAdapter | setUpWith(_:completionHandler:) |
setUp(with:completionHandler:) |
GADMediationAdSize | present(fromRootViewController:) |
present(from:) |
GADMediationAppOpenAd | present(fromRootViewController:) |
present(from:) |
GADMediationInterstitialAd | present(fromRootViewController:) |
present(from:) |
GADMediationRewardedAd | present(fromRootViewController:) |
present(from:) |
GAMInterstitialAd | load(withAdManagerAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
Thay đổi về API để kiểm soát trạng thái tắt tiếng video
Thuộc tính isMuted
và phương thức setMute:
trên GADVideoController
được thay thế bằng thuộc tính muted
.
Các thay đổi đối với quảng cáo thích ứng cùng dòng
Để tối ưu hoá việc sử dụng không gian, ban đầu, quảng cáo thích ứng cùng dòng không chiếm không gian trong khung. Giờ đây, việc gọi CGSizeFromGADAdSize(_:)
bằng kích thước quảng cáo thích ứng nội tuyến sẽ trả về chiều cao 0
cho đến khi SDK quảng cáo của Google trên thiết bị di động trả về một quảng cáo.
Đã xoá quảng cáo tìm kiếm tuỳ chỉnh
Các lớp sau đây sẽ bị xoá mà không có lớp thay thế:
GADDynamicHeightSearchBannerView
GADDynamicHeightSearchRequest
GADSearchBannerView
Thay đổi đối với mã lỗi
Các mã lỗi sau đây đã được thay đổi:
Lớp | Ghi chú |
---|---|
GADErrorMediationNoFill |
Lỗi hiện trả về dưới dạng GADErrorNoFill . |
GADErrorReceivedInvalidResponse |
Đã được thay thế bằng GADErrorReceivedInvalidAdString . |
Xoá GADSimulatorID
Đã xoá GADSimulatorID
. Theo mặc định, trình mô phỏng đã ở chế độ kiểm thử.
Các thay đổi đối với tiêu chí nhắm mục tiêu tuỳ chỉnh
Từ điển customTargeting
trên GADRequest
hiện sử dụng Any
thay vì String
làm loại giá trị. Điều này cho phép bạn truyền các giá trị số vào API.
Thay đổi đối với tham số bổ sung
- Việc truyền khoá vào
additionalParameters
không còn áp dụng tiêu chí nhắm mục tiêu tuỳ chỉnh cho các yêu cầu quảng cáo Ad Manager. Để áp dụng tiêu chí nhắm mục tiêu tuỳ chỉnh, hãy xem phần tiêu chí nhắm mục tiêu tuỳ chỉnh.
- Không còn hỗ trợ việc truyền khoá
max_ad_content_rating
vàoadditionalParameters
. Để đặt mức phân loại nội dung quảng cáo tối đa, hãy xem phần lọc nội dung quảng cáo.
Di chuyển từ phiên bản 10 sang phiên bản 11
Mục tiêu triển khai tối thiểu
Mục tiêu triển khai tối thiểu đã được tăng lên iOS 12.
Phiên bản Xcode tối thiểu
Phiên bản Xcode tối thiểu được hỗ trợ đã tăng lên 15.1.
Ngừng phân phát quảng cáo trên iOS 12
SDK quảng cáo trên thiết bị di động của Google phiên bản 11.0.0 chỉ phân phát quảng cáo trên các thiết bị chạy iOS 13 trở lên.
Xoá phần phụ thuộc GoogleAppMeasurement
Trong phiên bản 11.0.0, phần phụ thuộc trên GoogleAppMeasurement
đã bị xoá. Phần phụ thuộc này cung cấp nút bật/tắt chỉ số người dùng trong AdMob sẽ ngừng hoạt động từ đầu năm 2024. Để tiếp tục thu thập chỉ số người dùng trong AdMob, hãy liên kết ứng dụng AdMob của bạn với Firebase và tích hợp SDK Google Analytics cho Firebase vào ứng dụng.
Thay đổi đối với cách trình bày quảng cáo toàn màn hình
Những thay đổi sau đây sẽ ảnh hưởng đến nhiều định dạng quảng cáo:
- Mở ứng dụng
- Quảng cáo xen kẽ
- Được thưởng
- Quảng cáo xen kẽ có tặng thưởng
Tham số trình điều khiển thành phần hiển thị trong -canPresentFromRootViewController:error:
và -presentFromRootViewController:
có thể nhận giá trị rỗng. Nếu giá trị rỗng được truyền, quảng cáo sẽ được trình bày từ bộ điều khiển chế độ xem trên cùng trong hệ phân cấp bộ điều khiển chế độ xem.
Các phương thức đã bị xoá
Các phương thức sau đây đã bị xoá.
Loại v11.0.0 | Phương thức | Ghi chú |
---|---|---|
GADAppOpenAd | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) |
Thay vào đó, hãy sử dụng load(withAdUnitID adUnitID: String, request: GADRequest?) . |
GADMediationBannerAdEventDelegate | willBackgroundApplication() |
Không có loại thay thế. |
GADMediationInterstitialAdEventDelegate | willBackgroundApplication() |
Không có loại thay thế. |
GADMediationNativeAdEventDelegate | willBackgroundApplication() |
Không có loại thay thế. |
GADMediationRewardedAdEventDelegate | didRewardUser(with reward: GADAdReward) |
Thay vào đó, hãy sử dụng didRewardUser() . |
GADMediatedUnifiedNativeAdNotificationSource | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) |
Không có loại thay thế. |
GADRequestConfiguration | setSameAppKeyEnabled(_ enabled: Bool) |
Thay vào đó, hãy sử dụng setPublisherFirstPartyIDEnabled(_ enabled: Bool) . |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) |
Thay vào đó, hãy sử dụng thuộc tính tagForUnderAgeOfConsent . |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
Thay vào đó, hãy sử dụng thuộc tính tagForChildDirectedTreatment . |
Các thuộc tính đã bị xoá
Các thuộc tính sau đây sẽ bị xoá.
Lớp phiên bản 11.0.0 | Thuộc tính | Ghi chú |
---|---|---|
GADMediationAdConfiguration | hasUserLocation | Không có loại thay thế. |
userLatitude | ||
userLongitude | ||
userLocationAccuracyInMeters | ||
childDirectedTreatment | Thay vào đó, hãy sử dụng GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment . |
|
GADResponseInfo | adNetworkClassName | Thay vào đó, hãy sử dụng adNetworkClassName từ loadedAdNetworkResponseInfo . |
Xoá GADAdFormatUnknown
Xoá GADAdFormatUnknown
mà không thay thế.
Thay đổi đối với phiên bản SDK ghi nhật ký
Phiên bản 11.0.0 xoá sdkVersion
. Để ghi nhật ký phiên bản SDK Quảng cáo của Google trên thiết bị di động, hãy sử dụng versionNumber
.
Phiên bản 10.0.0
GADMobileAds.sharedInstance().sdkVersion
Phiên bản 11.0.0
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
Thay đổi đối với cách xử lý lỗi GADAdLoader
Kể từ phiên bản 11.0.0, GADAdLoader
sẽ không tạo yêu cầu quảng cáo nếu delegate
không tuân thủ giao thức uỷ quyền của các loại quảng cáo đã yêu cầu. Trước đây, tính năng này không hoạt động sau khi yêu cầu quảng cáo được thực hiện.
Thay đổi đối với hành vi kiểm thử
Hãy xem bảng cho thấy các điều kiện cập nhật khi các thuộc tính sau trả về true
.
Lớp | Thuộc tính |
---|---|
GADMediationAdConfiguration | isTestRequest |
GADCustomEventRequest | isTesting |
v10.0.0 | v11.0.0 |
|
|
Di chuyển từ phiên bản 9 sang phiên bản 10
Ngừng phân phát quảng cáo trên iOS 11
SDK quảng cáo trên thiết bị di động của Google phiên bản 10.0.0 chỉ phân phát quảng cáo trên các thiết bị chạy iOS 12 trở lên.
Việc nâng cấp lên SDK quảng cáo trên thiết bị di động của Google phiên bản 10.0.0 sẽ không khiến ứng dụng của bạn gặp lỗi trên các thiết bị iOS 11 và iOS 10. Tuy nhiên, quảng cáo sẽ không được phân phát trên các thiết bị đó.
Yêu cầu về mã ứng dụng Ad Manager
Hiện tại, mã ứng dụng Ad Manager bắt buộc phải có trong Info.plist
cho tất cả ứng dụng Ad Manager và phải ở định dạng ca-app-pub-################~##########
. Xem phần Cập nhật tệp Info.plist để biết thêm thông tin.
Yêu cầu về GoogleAppMeasurement.xcframework
Hiện tại, tất cả ứng dụng Ad Manager đều phải có GoogleAppMeasurement.xcframework. Nếu cài đặt SDK quảng cáo trên thiết bị di động của Google thông qua CocoaPods hoặc Trình quản lý gói Swift, thì bạn không cần làm gì thêm. Nếu bạn tự cài đặt khung ứng dụng, hãy xem phần Tải xuống theo cách thủ công để biết thêm thông tin.
Việc xây dựng chương trình bằng mã bit không còn được hỗ trợ nữa
Hiện tại, bạn phải tắt mã bit trong ứng dụng di động để tích hợp SDK quảng cáo trên thiết bị di động của Google.
Các loại đã bị xoá
Loại | Ghi chú |
---|---|
GADGender | Không có loại thay thế. |
GADMRewardBasedVideoAdNetworkAdapterProtocol | Tất cả các bộ chuyển đổi dàn xếp có tặng thưởng được nêu trong mục Chọn mạng đã ngừng sử dụng các giao thức này trong hơn một năm qua. Hãy sử dụng GADMediationAdapter cho hoạt động dàn xếp và các sự kiện tuỳ chỉnh. |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
Các thuộc tính đã bị xoá
Các thuộc tính sau đã bị xoá mà không có thuộc tính thay thế.
Lớp phiên bản 10.0.0 | Thuộc tính |
---|---|
GADMediationAdRequest | userBirthday |
userGender | |
userHasLocation | |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription | |
GADCustomEventRequest | userHasLocation |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription |
Di chuyển từ phiên bản 8 sang phiên bản 9
Ngừng phân phát quảng cáo trên iOS 10
SDK quảng cáo trên thiết bị di động của Google phiên bản 9.0.0 hỗ trợ phiên bản iOS 11 trở lên.
Việc nâng cấp lên SDK quảng cáo trên thiết bị di động của Google phiên bản 9.0.0 sẽ không khiến ứng dụng của bạn gặp lỗi trên các thiết bị iOS 10. Tuy nhiên, quảng cáo sẽ không được phân phát trên các thiết bị đó.
Thực thi nghiêm ngặt hơn việc kiểm soát thanh trạng thái
Kể từ phiên bản 9.0.0 trở lên, khi hiển thị quảng cáo ở định dạng toàn màn hình, ứng dụng của bạn phải đảm bảo rằng quảng cáo có thể kiểm soát việc hiển thị thanh trạng thái. Bạn sẽ thấy thông báo lỗi trong nhật ký nếu không đảm bảo được điều này.
Tuỳ thuộc vào bố cục cụ thể của trình kiểm soát chế độ xem trong ứng dụng của mình, bạn có thể không cần làm gì để đảm bảo điều này. Cân nhắc xem bạn có cần đặt thuộc tính childViewControllerForStatusBarHidden
trên rootViewController
của quảng cáo hay không.
Đổi tên adDidPresentFullScreenContent: thành adWillPresentFullScreenContent:
Cách thức hoạt động sẽ không thay đổi. Phương thức uỷ quyền được gọi ngay trước khi quảng cáo chuẩn bị xuất hiện, vì vậy, tên phương thức mới sẽ thể hiện chức năng của quảng cáo một cách chính xác hơn.
Xoá API cài đặt vị trí trên GADRequest
- (void)setLocationWithLatitude:longitude:accuracy:
đã bị xoá khỏi
GADRequest
vì Google không sử dụng dữ liệu vị trí để nhắm mục tiêu quảng cáo. Nếu bắt buộc, hãy sử dụng API của bên thứ ba để cung cấp thông tin cho các mạng quảng cáo bên thứ ba.
Ngừng sử dụng giao diện sự kiện tuỳ chỉnh
Sự kiện tuỳ chỉnh cho phép nhà xuất bản sử dụng tính năng Dàn xếp Ad Manager để thêm chế độ dàn xếp kiểu thác nước cho một mạng quảng cáo không thuộc danh sách mạng quảng cáo được hỗ trợ.
Tất cả giao thức sự kiện tuỳ chỉnh đều sẽ ngừng hoạt động. Thay vào đó, hãy sử dụng các giao thức GADMediationAdapter
và GADMediationAdEventDelegate
hiện có để triển khai các chức năng tương tự. Thay đổi này giúp cung cấp thông tin rõ ràng hơn và cho phép bạn tạo các sự kiện tuỳ chỉnh cho quảng cáo có tặng thưởng và quảng cáo kiểu cuộn xen kẽ mà trước đây chưa được hỗ trợ.
API
Bảng bên dưới liệt kê những API bộ chuyển đổi dàn xếp tương ứng với API sự kiện tuỳ chỉnh mà bạn nên sử dụng kể từ phiên bản 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBanner GADCustomEventInterstitial GADCustomEventNativeAd |
GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediationRewardedAd GADMediationNativeAd |
delegate
|
Trình xử lý hoàn thành lượt tải của mỗi hàm tải trong lớp GADMediationAdapter sẽ trả về thực thể đại diện
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
Không áp dụng | -loadInterscrollerAdFor |
|
Không áp dụng | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
Phương thức uỷ quyền
Bảng bên dưới liệt kê những phương thức uỷ quyền sự kiện quảng cáo dàn xếp tương ứng với các phương thức uỷ quyền sự kiện tuỳ chỉnh mà bạn nên sử dụng kể từ phiên bản 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBannerDelegate GADCustomEventInterstitialDelegate GADCustomEventNativeAdDelegate |
GADMediationAdEventDelegate | GADMediationAd |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd:
|
Trạng thái tải quảng cáo được đưa vào trình xử lý hoàn thành lượt tải của mỗi hàm tải trong lớp GADMediationAdapter
|
|
-customEventBanner:didFailAd: -customEventInterstitial:didFailAd:
|
||
-customEventBannerWasClicked: -customEventInterstitialWasClicked:
|
-reportClick |
|
-customEventBannerWill -customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid -customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
Những phương thức và hằng số đã bị xoá/thay thế khác
Những thay đổi đối với phương thức, hằng số hoặc thuộc tính | |
---|---|
Hằng số có tiền tố kGAD-
|
Đã xoá. Sử dụng hằng số có tiền tố GAD- .
|
GADAdNetworkResponseInfo
|
credentials đã bị xoá. Thay vào đó, hãy sử dụng adUnitMapping .
|
GAMRequest
|
kGAMSimulatorID trong GAMRequest không còn được dùng nữa.
Thay vào đó, hãy sử dụng GADSimulatorID trong GADRequestConfiguration .
|
GADCustomNativeAd
|
mediaView trong GADCustomNativeAd không còn được dùng nữa.
Thay vào đó, hãy sử dụng mediaContent .
|
API mua hàng trong ứng dụng trong GoogleMobileAds |
API inAppPurchase trong GoogleMobileAds đã
bị xoá.
|
Di chuyển từ phiên bản 7 sang phiên bản 8
SDK Quảng cáo trên thiết bị di động của Google phiên bản 8.0.0 có một vài thay đổi chính. Đồng thời, một số API sẽ được đổi tên và một số API sẽ bị xoá.
Nội dung cập nhật đối với API theo định dạng toàn màn hình
Kể từ phiên bản 8.0.0, quảng cáo xen kẽ và quảng cáo có tặng thưởng sẽ có chung một kiểu quảng cáo toàn màn hình chung để tăng tính nhất quán. Các API quảng cáo toàn màn hình mới này có hai điểm khác biệt chính so với các API quảng cáo toàn màn hình phiên bản 7:
Phương thức lớp tĩnh
load
.Trước đây, để tải/hiển thị một quảng cáo toàn màn hình, chúng ta làm như sau:
- Tạo một phiên bản đối tượng quảng cáo và giữ tệp tham chiếu đến đối tượng đó.
- Chỉ định một đại biểu xử lý các lệnh gọi lại tải và hiển thị.
- Tải một quảng cáo.
- Kiểm tra xem quảng cáo có được tải bằng cách sử dụng
isReady
hay không. - Hiển thị quảng cáo.
Trong phiên bản 8, cách thực hiện có hơi khác. Các lệnh gọi lại tải không còn là một phần của thực thể uỷ quyền nữa. Thay vào đó, các lệnh gọi lại đó được chuyển vào phương thức
load
dưới dạng trình xử lý hoàn thành:- Gọi một phương thức tải tĩnh trên lớp quảng cáo và cung cấp một trình xử lý tải hoàn thành.
- Trong lệnh gọi lại tải hoàn tất, hãy giữ tệp tham chiếu đến quảng cáo đã tải sẽ được trả về.
- Chỉ định một đại biểu xử lý các lệnh gọi lại hiển thị.
- Hiển thị quảng cáo.
Cách thực hiện mới mang lại các lợi ích sau:
- Tệp tham chiếu đến quảng cáo sẽ không được tạo nếu quảng cáo chưa được tải.
- Bạn không phải giữ một đối tượng quảng cáo trong khi đang tải.
Sự kiện quảng cáo nhất quán.
Loại sự kiện API hiện có API phiên bản 8 Sự kiện tải GADInterstitialDelegate
hoặcGADRewardedAdDelegate
GAMInterstitialAdLoadCompletionHandler
hoặcGADRewardedAdLoadCompletionHandler
Sự kiện trình bày GADFullScreenContentDelegate
Trước đây, để theo dõi bất kỳ sự kiện quảng cáo nào, bạn sẽ đăng ký một lớp triển khai giao thức
GADInterstitialDelegate
cho thuộc tính đại diện của quảng cáo xen kẽ hoặc đăng ký một lớp triển khai giao thứcGADRewardedAdDelegate
cho thuộc tính đại diện của quảng cáo có tặng thưởng, tuỳ thuộc vào định dạng mà bạn đang sử dụng. Thực thể đại diện tương tự này có các phương thức liên quan đến cả chu kỳ tải và trình bày của một quảng cáo.Với phiên bản 8, các sự kiện tải và trình bày là riêng biệt. Bây giờ, bạn có thể đăng ký
GADFullScreenContentDelegate
bất kỳ lúc nào trước khi hiển thị quảng cáo thay vì phải đặt một thực thể đại diện trước khi tải quảng cáo. Các sự kiện tải quảng cáo (cụ thể cho từng định dạng) chuyển thành một trình xử lý tải hoàn thành được chuyển vào phương thức tải.
Quảng cáo xen kẽ
Tải quảng cáo
Các đoạn mã dưới đây cho bạn biết cách tải một quảng cáo xen kẽ và theo dõi các sự kiện khi quảng cáo tải thành công hoặc không tải được.
phiên bản 7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: DFPInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/21775744923/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:@"/21775744923/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:@"/21775744923/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; }]; }
Quảng cáo hiển thị hình ảnh
phiên bản 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"); } }
Sự kiện quảng cáo trình bày
Các đoạn mã dưới đây cho bạn thấy cách xử lý các lệnh gọi lại khi quảng cáo hiển thị (thành công hoặc không thành công) và khi quảng cáo bị loại bỏ.
phiên bản 7
Swift
override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/21775744923/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:"/21775744923/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:@"/21775744923/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."); }
Được thưởng
Tải quảng cáo
phiên bản 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(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; }
Hiển thị quảng cáo và xử lý phần thưởng
Quảng cáo có tặng thưởng yêu cầu bạn xử lý sự kiện khi người dùng nhận được phần thưởng. Với phiên bản 7 của API GADRewardedAd
, bạn triển khai rewardedAd:userDidEarnReward:
trong giao thức GADRewardedAdDelegate
.
Đối với phiên bản 8, bạn triển khai GADUserDidEarnRewardHandler
để hiển thị quảng cáo.
phiên bản 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"); } }
Sự kiện quảng cáo trình bày
Với API GADRewardedAd
, bạn chuyển GADRewardedAdDelegate
đến phương thức hiển thị quảng cáo. Với API GADRewardedAd
, bạn đặt GADFullscreenContentDelegate
làm thuộc tính trên quảng cáo trước khi hiển thị quảng cáo.
phiên bản 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 = 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."); }
Xoá API GADRewardedBasedVideoAd cũ
API GADRewardedAd
mới được ra mắt lần đầu vào tháng 3 năm 2019 và là API có tặng thưởng được ưa thích trong hơn 18 tháng qua. API này có nhiều tính năng nâng cao hơn so với API GADRewardedBasedVideoAd
cũ, kể cả khả năng tải nhiều quảng cáo có tặng thưởng cùng lúc.
API GADRewardedBasedVideoAd
cũ sẽ bị xoá trong SDK phiên bản 8.0.0.
Biểu ngữ thông minh sẽ ngừng hoạt động và được thay thế bằng biểu ngữ thích ứng
Quảng cáo biểu ngữ thông minh sẽ ngừng hoạt động và được thay thế bằng quảng cáo biểu ngữ thích ứng. Biểu ngữ thích ứng mang lại hiệu quả hoạt động vượt trội và tính linh hoạt cao hơn trong việc đặt chiều rộng quảng cáo. Nếu muốn tiếp tục sử dụng biểu ngữ có chiều rộng đầy đủ, bạn vẫn có thể làm vậy bằng cách sử dụng biểu ngữ thích ứng, theo cách minh hoạ trong đoạn mã sau đây:
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
Xoá lệnh gọi lại ứng dụng
Lệnh gọi lại willLeaveApplication
cho tất cả các định dạng quảng cáo đã bị xoá và được thay thế bằng phương thức applicationDidEnterBackground:
và sceneDidEnterBackground:
. Khi sử dụng API ở cấp hệ điều hành, bạn sẽ nhận được thông báo mỗi khi người dùng rời khỏi ứng dụng, bất kể việc đó có phải là do một hành động tương tác với quảng cáo hay không.
Xin lưu ý rằng lệnh gọi lại willLeaveApplication
không có chức năng như một trình xử lý lượt nhấp quảng cáo, và việc dựa vào lệnh gọi lại này để báo cáo lượt nhấp sẽ không cung cấp chỉ số chính xác. Ví dụ: một lượt nhấp vào biểu tượng Lựa chọn quảng cáo làm khởi chạy một trình duyệt bên ngoài đã kích hoạt lệnh gọi lại, nhưng không được tính là một lượt nhấp.
Đổi tên lớp
Bảng dưới đây liệt kê các lớp cụ thể đã đổi tên hoặc bị xoá trong phiên bản 8. Tóm tắt:
- Tất cả các lớp có liên quan đến
GADUnifiedNativeAd
đều đã được đổi tên thànhGADNativeAd
. GADRewardBasedVideoAd
,GADNativeExpressAdView
vàGADInstreamAd
đã bị xoá.- Tất cả các lớp có tiền tố
DFP
đều đã được thay thế bằng tiền tốGAM
.
Lớp phiên bản 7.68.0 | Lớp phiên bản 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 | Đã xoá |
GADInterstitial | GADInterstitialAd |
GADNativeExpressAdView | Đã xoá |
GADRewardBasedVideoAd | Đã xoá |
GADInstreamAd | Đã xoá |
GADInstreamAdView | Đã xoá |
Xoá/thay thế một số phương thức
Bảng dưới đây liệt kê các thay đổi cụ thể trong phiên bản 8. Tóm tắt:
- Các phương thức và thuộc tính không dùng nữa trước đây đã bị xoá.
- Phương thức uỷ quyền
-willLeaveApplication:
đều đã bị xoá cho tất cả định dạng. - Tên lớp mạng quảng cáo đã di chuyển sang thuộc tính
GADResponseInfo
. - Mã nhận dạng thiết bị thử nghiệm đã di chuyển sang thuộc tính
GADRequestConfiguration
.
Lớp phiên bản 7.68.0 | API phiên bản 7.68.0 | API phiên bản 8.0.0 | Ghi chú |
---|---|---|---|
GADMobileAds | +configureWithApplicationID: | -startWithCompletionHandler: | Mã ứng dụng hiện được đặt trong Info.plist. |
+disableAutomatedInApp |
-disableAutomatedInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
Thuộc tính testDeviceIdentifiers hiện sẽ áp dụng cho tất cả các yêu cầu quảng cáo, trong khi thuộc tính testDevices cũ được đặt theo yêu cầu. |
gender | Đã xoá | ||
sinh nhật | Đã xoá | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
Đã xoá | ||
-setLocationWithDescription: | -setLocationWith |
||
-tagForChildDirectedTreatment: | [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment] | ||
GADErrorCode | kGADError* | GADError* | Tiền tố k bị loại khỏi tất cả các hằng số mã lỗi.
|
GADBannerView | hasAutoRefreshed | autoloadEnabled | |
inAppPurchaseDelegate | Đã xoá | ||
mediatedAdView | Đã xoá | ||
adNetworkClassName | responseInfo |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerViewOptions | -adSizeDelegate | Đã xoá | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillLeaveApplication: | Đã xoá | ||
GADNativeCustomTemplateAd | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GADNativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | Đã xoá | |
isReady | Đã xoá | Thay vào đó, hãy sử dụng canPresentFrom |
|
hasBeenUsed | Đã xoá | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | responseInfo |
||
-interstitialWill |
Đã xoá | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |