Yandex Mobile Ads SDK 第 8 版对 API 进行了一系列调整,以改善开发者的使用体验。
若项目使用 Objective-C,请注意 第 14 节 中关于 MainActor 的说明,以便正确处理 MainActor 隔离的类。请在主线程上访问它们。
主要变更
1. AdRequest 的变更
- 所有广告类型请使用
AdRequest。
- 已移除
AdRequestConfiguration、NativeAdRequestConfiguration 以及所有可变(Mutable)请求类。
adUnitID 现作为 AdRequest 初始化的必填参数传入。
|
类
|
状态
|
|
AdRequestConfiguration
|
已删除。请使用 AdRequest
|
|
NativeAdRequestConfiguration
|
已删除。请使用 AdRequest 与 NativeAdOptions
|
|
MutableAdRequest
|
已删除
|
|
MutableAdRequestConfiguration
|
已删除
|
|
MutableNativeAdRequestConfiguration
|
已删除
|
示例
|
SDK 7
|
let configuration = AdRequestConfiguration(adUnitID: "R-M-XXXXX-YY")
loader.loadAd(with: configuration)
|
|
SDK 8
|
let request = AdRequest(adUnitID: "R-M-XXXXX-YY") loader.loadAd(with: request) { … }
|
|
SDK 7
|
YMAAdRequestConfiguration *configuration =
[[YMAAdRequestConfiguration alloc] initWithAdUnitID:@"R-M-XXXXX-YY"];
[loader loadAdWithConfiguration:configuration];
|
|
SDK 8
|
YMAAdRequest *request =
[[YMAAdRequest alloc] initWithAdUnitID:@"R-M-XXXXX-YY"];
[loader loadAdWithRequest:request
completionHandler:^(YMAInterstitialAd * _Nullable ad,
NSError * _Nullable error) {
if (ad) {
} else {
}
}];
|
2. Targeting 的变更
- 已从
AdRequest 中移除字段 age、gender、location、contextQuery 和 contextTags。
- 请使用新类
AdTargeting 管理定向参数。
类 AdTargetInfo 已重命名为 AdTargeting;AdRequestTokenConfiguration 与 BidderTokenRequestConfiguration 中的字段 targetInfo 已重命名为 targeting。
|
类
|
状态
|
|
AdTargetInfo
|
重命名为 AdTargeting
|
|
类
|
属性
|
状态
|
|
AdRequest
|
age
|
已删除。请使用 AdTargeting.age
|
|
gender
|
已删除。请使用 AdTargeting.gender
|
|
location
|
已删除。请使用 AdTargeting.location
|
|
contextQuery
|
已删除。请使用 AdTargeting.contextQuery
|
|
contextTags
|
已删除。请使用 AdTargeting.contextTags
|
|
targeting
|
已新增
|
|
AdTargeting
|
targetInfo
|
重命名为 targeting
|
示例
|
SDK 7
|
let request = AdRequest(
adUnitID: "R-M-XXXXX-YY",
age: 25,
gender: kYMAGenderMale,
location: location
)
|
|
SDK 8
|
let targeting = AdTargeting(
age: 25,
gender: .male,
location: location
)
let request = AdRequest(adUnitID: "R-M-XXXXX-YY", targeting: targeting)
|
|
SDK 7
|
YMAAdRequest *request = [[YMAAdRequest alloc] initWithAdUnitID:@"R-M-XXXXX-YY"
age:@(25)
gender:kYMAGenderMale
location:location];
|
|
SDK 8
|
YMAAdTargeting *targeting = [[YMAAdTargeting alloc] initWithAge:@(25)
gender:YMAGender.male
location:location
contextQuery:nil
contextTags:nil];
YMAAdRequest *request = [[YMAAdRequest alloc] initWithAdUnitID:@"R-M-XXXXX-YY"
targeting:targeting];
|
3. 广告加载器的变更
- 已移除加载委托;加载结果通过
completion 回调返回。
adUnitID 现通过 AdRequest 传入。
|
类
|
加载器
|
状态
|
|
AppOpenAdLoader
|
loadAd(with:) + 委托
|
替换为 loadAd(with:completion:)
|
|
InterstitialAdLoader
|
loadAd(with:) + 委托
|
替换为 loadAd(with:completion:)
|
|
RewardedAdLoader
|
loadAd(with:) + 委托
|
替换为 loadAd(with:completion:)
|
|
NativeAdLoader
|
loadAd(with:) + 委托
|
替换为 loadAd(with:options:completion:)
|
|
NativeBulkAdLoader
|
loadAds(with:adsCount:) + 委托
|
替换为 loadAds(with:adsCount:options:completion:)
|
|
SliderAdLoader
|
loadAd(with:) + 委托
|
替换为 loadAd(with:options:completion:)
|
|
类
|
状态
|
|
AppOpenAdLoaderDelegate
|
已删除
|
|
InterstitialAdLoaderDelegate
|
|
RewardedAdLoaderDelegate
|
|
NativeAdLoaderDelegate
|
|
NativeBulkAdLoaderDelegate
|
|
SliderAdLoaderDelegate
|
示例
|
SDK 7
|
let configuration = AdRequestConfiguration(adUnitID: "R-M-XXXXX-YY")
interstitialAdLoader.delegate = self
interstitialAdLoader.loadAd(with: configuration)
let nativeConfiguration = NativeAdRequestConfiguration(adUnitID: "R-M-XXXXX-YY")
nativeAdLoader.delegate = self
nativeAdLoader.loadAd(with: nativeConfiguration)
|
|
SDK 8
|
let request = AdRequest(adUnitID: "R-M-XXXXX-YY")
interstitialAdLoader.loadAd(with: request) { result in
switch result {
case .success(let ad):
case .failure(let error):
}
}
let options = NativeAdOptions()
nativeAdLoader.loadAd(with: request, options: options) { result in
switch result {
case .success(let ad):
case .failure(let error):
}
}
|
|
SDK 7
|
YMAAdRequestConfiguration *configuration =
[[YMAAdRequestConfiguration alloc] initWithAdUnitID:@"R-M-XXXXX-YY"];
interstitialAdLoader.delegate = self;
[interstitialAdLoader loadAdWithConfiguration:configuration];
YMANativeAdRequestConfiguration *nativeConfig =
[[YMANativeAdRequestConfiguration alloc] initWithAdUnitID:@"R-M-XXXXX-YY"];
nativeAdLoader.delegate = self;
[nativeAdLoader loadAdWithConfiguration:nativeConfig];
|
|
SDK 8
|
YMAAdRequest *request =
[[YMAAdRequest alloc] initWithAdUnitID:@"R-M-XXXXX-YY"];
[interstitialAdLoader loadAdWithRequest:request
completionHandler:^(YMAInterstitialAd * _Nullable ad,
NSError * _Nullable error) {
if (ad) {
} else {
}
}];
YMANativeAdOptions *options = [[YMANativeAdOptions alloc] init];
[nativeAdLoader loadAdWithRequest:request
options:options
completionHandler:^(id<YMANativeAd> _Nullable ad,
NSError * _Nullable error) {
if (ad) {
} else {
}
}];
|
3.1 Structured Concurrency 支持
所有广告加载器均已支持 Swift Structured Concurrency(async/await)。
|
加载器
|
方法
|
状态
|
|
AppOpenAdLoader
|
loadAd(with:)
|
已新增
|
|
InterstitialAdLoader
|
loadAd(with:)
|
|
RewardedAdLoader
|
loadAd(with:)
|
|
NativeAdLoader
|
loadAd(with:options:)
|
|
NativeBulkAdLoader
|
loadAds(with:adsCount:options:)
|
|
SliderAdLoader
|
loadAd(with:options:)
|
示例
let request = AdRequest(adUnitID: "R-M-XXXXX-YY")
let interstitialAd = try await interstitialAdLoader.loadAd(with: request)
let rewardedAd = try await rewardedAdLoader.loadAd(with: request)
let appOpenAd = try await appOpenAdLoader.loadAd(with: request)
let options = NativeAdOptions()
let nativeAd = try await nativeAdLoader.loadAd(with: request, options: options)
let sliderAd = try await sliderAdLoader.loadAd(with: request, options: options)
let nativeAds = try await nativeBulkAdLoader.loadAds(with: request, adsCount: 3, options: options)
Structured Concurrency 仅在 Swift 中可用。
4. Banner API 的变更
- 类
AdView 重命名为 BannerAdView,协议 AdViewDelegate 重命名为 BannerAdViewDelegate。
- 已从
BannerAdView 中移除属性 adUnitID;现于每次加载前通过 AdRequest 的构造传入 adUnitID。
BannerAdSize 的工厂方法已重命名。
|
类
|
状态
|
|
AdView
|
重命名为 BannerAdView
|
|
AdViewDelegate
|
重命名为 BannerAdViewDelegate
|
|
类
|
属性
|
状态
|
|
BannerAdView
|
adViewDidLoad
|
重命名为 bannerAdViewDidLoad
|
|
adViewDidFailLoading
|
重命名为 bannerAdViewDidFailLoading
|
|
adViewDidClick
|
重命名为 bannerAdViewDidClick
|
|
adView(_:didTrackImpression:)
|
重命名为 bannerAdView(_:didTrackImpression:)
|
|
AdView(adUnitID:adSize:)
|
替换为 BannerAdView(adSize:)
|
|
AdView.adUnitID
|
替换为 BannerAdView.adInfo?.adUnitID
|
|
AdView.loadAd()
|
已删除
|
|
AdView.loadAd(with: AdRequest?)
|
替换为 BannerAdView.loadAd(with: AdRequest)
|
|
BannerAdSize
|
fixedSize(withWidth:height:)
|
重命名为 fixed(width:height:)
|
|
inlineSize(withWidth:maxHeight:)
|
重命名为 inline(width:maxHeight:)
|
|
stickySize(withContainerWidth:)
|
重命名为 sticky(containerWidth:)
|
示例
|
SDK 7
|
let adSize = BannerAdSize.stickySize(withContainerWidth: screenWidth)
let adView = AdView(adUnitID: "R-M-XXXXX-YY", adSize: adSize)
adView.delegate = self
adView.loadAd()
|
|
SDK 8
|
let adSize = BannerAdSize.sticky(containerWidth: screenWidth)
let bannerAdView = BannerAdView(adSize: adSize)
bannerAdView.delegate = self
let request = AdRequest(adUnitID: "R-M-XXXXX-YY")
bannerAdView.loadAd(with: request)
|
|
SDK 7
|
YMABannerAdSize *adSize = [YMABannerAdSize stickySizeWithContainerWidth:screenWidth];
YMAAdView *adView = [[YMAAdView alloc] initWithAdUnitID:@"R-M-XXXXX-YY"
adSize:adSize];
adView.delegate = self;
[adView loadAd];
|
|
SDK 8
|
YMABannerAdSize *adSize = [YMABannerAdSize stickyWithContainerWidth:screenWidth];
YMABannerAdView *bannerAdView = [[YMABannerAdView alloc] initWithAdSize:adSize];
bannerAdView.delegate = self;
YMAAdRequest *request = [[YMAAdRequest alloc] initWithAdUnitID:@"R-M-XXXXX-YY"];
[bannerAdView loadAdWithRequest:request];
|
5. AdInfo 的变更
- 已移除广告对象上的属性
info、adAttributes、creativeID、campaignID。
- 请使用
adInfo;adInfo 中部分属性名称也已调整。
|
类
|
属性
|
状态
|
|
AdInfo
|
adUnitId
|
重命名为 adUnitID
|
|
data
|
重命名为 extraData
|
|
adSize
|
已删除
|
|
partnerText
|
已新增
|
|
BannerAdView,
NativeAd,
SliderAd,
AppOpenAd,
InterstitialAd,
RewardedAd
|
info
|
替换为 adInfo.extraData
|
|
adAttributes
|
替换为 adInfo.creatives
|
|
creativeID
|
替换为 adInfo.creatives[i].creativeID
|
|
campaignID
|
替换为 adInfo.creatives[i].campaignID
|
|
Creative
|
placeID
|
已新增
|
|
offerID
|
已新增
|
示例
|
SDK 7
|
let attributes = nativeAd.adAttributes
let info = nativeAd.info
let creativeID = interstitialAd.creativeID
let campaignID = interstitialAd.campaignID
let adUnitId = interstitialAd.adInfo.adUnitId
let size = bannerAdView.adInfo.adSize
|
|
SDK 8
|
let creatives = nativeAd.adInfo.creatives
let extraData = nativeAd.adInfo.extraData
if let creative = interstitialAd.adInfo.creatives.first {
let creativeID = creative.creativeID
let campaignID = creative.campaignID
let placeID = creative.placeID
let offerID = creative.offerID
}
let adUnitID = interstitialAd.adInfo.adUnitID
let partnerText = interstitialAd.adInfo.partnerText
|
|
SDK 7
|
NSArray *attributes = nativeAd.adAttributes;
NSDictionary *info = nativeAd.info;
NSString *creativeID = interstitialAd.creativeID;
NSString *campaignID = interstitialAd.campaignID;
NSString *adUnitId = interstitialAd.adInfo.adUnitId;
YMAAdSize *size = bannerAdView.adInfo.adSize;
|
|
SDK 8
|
NSArray<YMACreative *> *creatives = nativeAd.adInfo.creatives;
NSDictionary *extraData = nativeAd.adInfo.extraData;
YMACreative *creative = interstitialAd.adInfo.creatives.firstObject;
if (creative != nil) {
NSString *creativeID = creative.creativeID;
NSString *campaignID = creative.campaignID;
NSString *placeID = creative.placeID;
NSString *offerID = creative.offerID;
}
NSString *adUnitID = interstitialAd.adInfo.adUnitID;
NSString *partnerText = interstitialAd.adInfo.partnerText;
|
6. SDK 主类的变更
- 类
MobileAds 重命名为 YandexAds。
- 隐私相关方法与属性已迁移至新类,并采用新名称。
|
类
|
状态
|
|
MobileAds
|
重命名为 YandexAds
|
|
MobileAds.sdkVersion
|
替换为 YandexAds.sdkVersion.stringValue
|
|
MobileAds.setLocationTrackingEnabled(_:)
|
重命名为 YandexAds.setLocationTracking(_:)
|
|
MobileAds.setAgeRestrictedUser(_:)
|
重命名为 YandexAds.setAgeRestricted(_:)
|
|
MobileAds.setUserConsent(_:)
|
迁移至 YandexAds.setUserConsent(_:)
|
|
YMANativeAdView
|
重命名为 NativeAdView
|
|
YMANativeMediaView
|
重命名为 NativeMediaView
|
示例
|
SDK 7
|
import YandexMobileAds
MobileAds.setLocationTrackingEnabled(true)
MobileAds.setAgeRestrictedUser(false)
MobileAds.setUserConsent(true)
let version = MobileAds.sdkVersion
|
|
SDK 8
|
import YandexMobileAds
YandexAds.setLocationTracking(true)
YandexAds.setAgeRestricted(false)
YandexAds.setUserConsent(true)
let version = YandexAds.sdkVersion.stringValue
|
|
SDK 7
|
[YMAMobileAds setLocationTrackingEnabled:YES];
[YMAMobileAds setAgeRestrictedUser:NO];
[YMAMobileAds setUserConsent:YES];
NSString *version = YMAMobileAds.sdkVersion;
|
|
SDK 8
|
[YMAYandexAds setLocationTracking:YES];
[YMAYandexAds setAgeRestricted:NO];
[YMAYandexAds setUserConsent:YES];
NSString *version = YMAYandexAds.sdkVersion.stringValue;
|
7. 广告对象委托的变更
AppOpenAdDelegate、InterstitialAdDelegate、RewardedAdDelegate、NativeAdDelegate、SliderAdDelegate 的委托方法不再为可选;现均需实现。
展示相关方法
|
类
|
方法
|
状态
|
|
RewardedAdDelegate
|
rewardedAdDelegate(
_:didFailToShowWithError:)
|
重命名为
rewardedAdDelegate(
_:didFailToShow:)
|
|
InterstitialAdDelegate
|
interstitialAdDelegate(
_:didFailToShowWithError:)
|
重命名为
interstitialAdDelegate(
_:didFailToShow:)
|
|
AppOpenAdDelegate
|
appOpenAdDelegate(
_:didFailToShowWithError:)
|
重命名为
appOpenAdDelegate(
_:didFailToShow:)
|
展示跟踪方法
|
类
|
方法
|
状态
|
|
NativeAdDelegate
|
nativeAd(
_:didTrackImpressionWith:)
|
重命名为
nativeAd(
_:didTrackImpression:)
|
|
RewardedAdDelegate
|
rewardedAdDelegate(
_:didTrackImpressionWith:)
|
重命名为
rewardedAdDelegate(
_:didTrackImpression:)
|
|
InterstitialAdDelegate
|
interstitialAdDelegate(
_:didTrackImpressionWith:)
|
重命名为
interstitialAdDelegate(
_:didTrackImpression:)
|
|
AppOpenAdDelegate
|
appOpenAdDelegate(
_:didTrackImpressionWith:)
|
重命名为
appOpenAdDelegate(
_:didTrackImpression:)
|
|
SliderAdDelegate
|
sliderAdDelegate(
_:didTrackImpressionWith:)
|
重命名为
sliderAdDelegate(
_:didTrackImpression:)
|
已删除的委托方法
|
委托
|
方法
|
状态
|
|
AdViewDelegate
|
close(_:)
|
已删除
|
|
viewControllerForPresentingModalView()
|
|
adViewWillLeaveApplication
|
|
adView(_:willPresentScreen:)
|
|
adView(_:didDismissScreen:)
|
|
NativeAdDelegate
|
close(_:)
|
|
viewControllerForPresentingModalView()
|
|
nativeAdWillLeaveApplication
|
|
nativeAd(_:willPresentScreen:)
|
|
nativeAd(_:didDismissScreen:)
|
|
SliderAdDelegate
|
sliderAdDidClose(_:)
|
|
sliderAdWillLeaveApplication
|
|
sliderAd(_:willPresentScreen:)
|
|
sliderAd(_:didDismissScreen:)
|
8. 原生广告:Warning 的变更
NativeAdAssets 中字段 warning 的类型由 String? 改为 NativeAdWarning?。
- 在
NativeAdWarning 中新增字段 minimumRequiredArea,用于说明带 warning 的资源所需的最小广告区域占比。
|
类
|
字段
|
状态
|
|
NativeAdAssets
|
warning: String?
|
类型改为 warning: NativeAdWarning?
|
|
NativeAdWarning
|
value: String
|
已新增
|
|
minimumRequiredArea: Double
|
已新增
|
示例
|
SDK 7
|
let warningText: String? = nativeAd.adAssets.warning
label.text = warningText
|
|
SDK 8
|
let warning: NativeAdWarning? = nativeAd.adAssets.warning
label.text = warning?.value
|
|
SDK 7
|
NSString *warningText = nativeAd.adAssets.warning;
label.text = warningText;
|
|
SDK 8
|
YMANativeAdWarning *warning = nativeAd.adAssets.warning;
label.text = warning.value;
|
在 NativeAdMedia 中新增属性 hasVideo。
|
类
|
属性
|
状态
|
|
NativeAdMedia
|
hasVideo: Bool
|
已新增
|
示例
if let media = nativeAd.adAssets.media, media.hasVideo {
}
if (nativeAd.adAssets.media != nil && nativeAd.adAssets.media.hasVideo) {
}
10. NativeAd 与 SliderAd:loadImages 的变更
- 方法
loadImages() 重命名为 loadImages(completionHandler:)。
- 参数
completionHandler 取代协议观察者 NativeAdImageLoadingObserver。
- 新增异步版本
loadImages()。
|
类
|
状态
|
|
NativeAdImageLoadingObserver
|
已删除
|
|
类
|
方法
|
状态
|
|
NativeAd
|
loadImages() + NativeAdImageLoadingObserver
|
替换为 loadImages(completionHandler:) / loadImages()(async)
|
|
SliderAd
|
loadImages() + NativeAdImageLoadingObserver
|
替换为 loadImages(completionHandler:) / loadImages()(async)
|
适用于:NativeAd、SliderAd。
示例
|
SDK 7
|
nativeAd.addImageLoadingObserver(self)
nativeAd.loadImages()
sliderAd.addImageLoadingObserver(self)
sliderAd.loadImages()
|
|
SDK 8
|
nativeAd.loadImages { [weak self] in
}
await nativeAd.loadImages()
sliderAd.loadImages { [weak self] in
}
await sliderAd.loadImages()
|
|
SDK 7
|
[nativeAd addImageLoadingObserver:self];
[nativeAd loadImages];
[sliderAd addImageLoadingObserver:self];
[sliderAd loadImages];
|
|
SDK 8
|
[nativeAd loadImagesWithCompletionHandler:^{
}];
[sliderAd loadImagesWithCompletionHandler:^{
}];
|
11. 移除 VideoController
已删除属性 videoController 以及关联类 VideoController、VideoDelegate。
|
属性
|
状态
|
|
AdView.videoController
|
已删除
|
|
BannerAdView.videoController
|
|
VideoController
|
|
VideoDelegate
|
12. 移除原生模板
原生模板已完全移除,相关类均不再可用。
|
模板
|
状态
|
|
NativeTemplateAppearance
|
已删除
|
|
MutableNativeTemplateAppearance
|
|
NativeTemplateHorizontalOffset
|
|
NativeBannerView
|
|
ButtonAppearance
|
|
MutableButtonAppearance
|
|
ImageAppearance
|
|
MutableImageAppearance
|
|
LabelAppearance
|
|
MutableLabelAppearance
|
|
RatingAppearance
|
|
MutableRatingAppearance
|
|
SizeConstraint
|
|
MutableSizeConstraint
|
|
SizeConstraintType
|
|
YMAHorizontalOffset
|
13. 已删除的常量与错误类型
|
常量与错误类型
|
状态
|
|
kYMAAdsErrorDomain
|
已删除
|
|
kYMANativeAdErrorDomain
|
已删除
|
|
kYMAGenderFemale, kYMAGenderMale
|
替换为类 Gender
|
|
YMAVersion 中的常量
|
替换为 YandexAds.sdkVersion.stringValue
|
|
MobileAds.sdkVersion
|
替换为 YandexAds.sdkVersion.stringValue
|
|
AdErrorCode
|
已删除
|
|
NativeErrorCode
|
已删除
|
|
Version.prereleaseIdentifiers
|
已删除
|
|
Version.buildMetadataIdentifiers
|
已删除
|
|
isYandexMobileAdsError(在 Error/NSError 上)
|
已删除
|
|
isYandexMobileNativeAdsError(在 Error/NSError上)
|
已删除
|
14. Swift 6、MainActor 与 Sendable
- SDK 使用 Swift 6 构建。
- 部分类与协议现由
MainActor 隔离;另有一个协议要求 Sendable。
MainActor 隔离的类
|
类
|
|
AppOpenAd
|
|
InterstitialAd
|
|
RewardedAd
|
|
AudioSessionManager
|
|
NativeVideoPlaybackControls
|
MainActor 隔离的协议
|
协议
|
|
AppOpenAdDelegate
|
|
InterstitialAdDelegate
|
|
RewardedAdDelegate
|
|
NativeAd
|
|
NativeAdDelegate
|
|
SliderAd
|
|
SliderAdDelegate
|
|
BannerAdViewDelegate
|
协议 NativeAdImageLoadingObserver 已删除;图片加载通过 completion handler 或 async/await 处理。
15. 其他变更
|
类
|
对象
|
状态
|
|
Rating
|
setRating(_:) / rating()
|
替换为属性 Rating.rating
|
|
NativeAd
|
bind(toSliderView:)
|
迁移至 SliderAd.bind(with:)
|
|
NativeVideoPlaybackProgressControl
|
reset
|
已删除
|
|
MobileAds
|
audioSessionManager()
|
替换为属性 YandexAds.audioSessionManager
|
示例
|
SDK 7
|
rating.setRating(4.5)
let value = rating.rating()
let audioManager = MobileAds.audioSessionManager()
|
|
SDK 8
|
rating.rating = 4.5
let audioManager = YandexAds.audioSessionManager
|
|
SDK 7
|
[rating setRating:4.5];
CGFloat value = [rating rating];
YMAAudioSessionManager *audioManager = [YMAMobileAds audioSessionManager];
|
|
SDK 8
|
rating.rating = 4.5;
YMAAudioSessionManager *audioManager = YMAYandexAds.audioSessionManager;
|
1. 联盟适配器 AdapterIdentity 的变更
- 新增通过
AdapterIdentity 标识联盟适配器的机制。
- 不再使用参数
mediationNetworkName。
- 适配器标识需在 SDK 初始化前通过
YandexAds.setAdapterIdentity(_:) 全局设置。
|
类
|
参数
|
状态
|
|
BidderTokenLoader
|
BidderTokenLoader(mediationNetworkName:)
|
替换为 BidderTokenLoader()
|
|
YandexAds
|
MobileAds.initialize()
|
替换为 YandexAds.setAdapterIdentity(_:) + YandexAds.initializeSDK()
|
|
AdapterIdentity
|
AdapterIdentity(
adapterNetworkName:adapterVersion:adapterNetworkVersion:)
|
已新增
|
示例
|
SDK 7
|
let tokenLoader = BidderTokenLoader(mediationNetworkName: "AdMob")
let config = BidderTokenRequestConfiguration(adType: .interstitial)
tokenLoader.loadBidderToken(requestConfiguration: config) { ... }
MobileAds.initialize()
|
|
SDK 8
|
let tokenLoader = BidderTokenLoader()
let request = BidderTokenRequest.interstitial()
tokenLoader.loadBidderToken(request: request) { ... }
let adapterIdentity = AdapterIdentity(
adapterNetworkName: "AdMob",
adapterVersion: "1.0.0",
adapterNetworkVersion: "23.5.0"
)
YandexAds.setAdapterIdentity(adapterIdentity)
YandexAds.initializeSDK()
|
|
SDK 7
|
YMABidderTokenLoader *tokenLoader =
[[YMABidderTokenLoader alloc] initWithMediationNetworkName:@"AdMob"];
YMABidderTokenRequestConfiguration *config =
[[YMABidderTokenRequestConfiguration alloc] initWithAdType:YMAAdTypeInterstitial];
[tokenLoader loadBidderTokenWithRequestConfiguration:config
completionHandler:^(NSString *token) { ... }];
[YMAMobileAds initialize];
|
|
SDK 8
|
YMABidderTokenLoader *tokenLoader = [[YMABidderTokenLoader alloc] init];
YMABidderTokenRequest *request = [YMABidderTokenRequest interstitial];
[tokenLoader loadBidderTokenWithRequest:request
completionHandler:^(NSString *token) { ... }];
YMAAdapterIdentity *identity =
[[YMAAdapterIdentity alloc] initWithAdapterNetworkName:@"AdMob"
adapterVersion:@"1.0.0"
adapterNetworkVersion:@"23.5.0"];
[YMAYandexAds setAdapterIdentity:identity];
[YMAYandexAds initializeSDK];
|
2. BidderTokenRequest 的变更
- 类
BidderTokenRequestConfiguration 重命名为 BidderTokenRequest。
- 构造器与公开属性(
targetInfo、bannerAdSize、parameters)已迁移至工厂方法的参数。
|
类
|
状态
|
|
BidderTokenRequestConfiguration
|
重命名为 BidderTokenRequest
|
|
类
|
属性
|
状态
|
|
BidderTokenRequestConfiguration
|
init(adType: .banner) + .bannerAdSize
|
替换为
BidderTokenRequest.banner(
size:targeting:parameters:)
|
|
BidderTokenRequestConfiguration
|
init(adType: .interstitial) + .targetInfo
|
替换为
BidderTokenRequest.interstitial(
targeting:parameters:)
|
|
BidderTokenRequestConfiguration
|
init(adType: .rewarded) + .targetInfo
|
替换为
BidderTokenRequest.rewarded(
targeting:parameters:)
|
|
BidderTokenRequestConfiguration
|
init(adType: .native) + .targetInfo
|
替换为
BidderTokenRequest.native(
targeting:parameters:)
|
|
BidderTokenRequestConfiguration
|
init(adType: .appOpenAd) + .targetInfo
|
替换为
BidderTokenRequest.appOpenAd(
targeting:parameters:)
|
|
BidderTokenLoader
|
loadBidderToken(
requestConfiguration:completionHandler:)
|
重命名为
loadBidderToken(
request:completionHandler:)
|
适用于:使用 BidderTokenLoader 的聚合适配器。
示例
|
SDK 7
|
let config = BidderTokenRequestConfiguration(adType: .banner)
config.bannerAdSize = adSize
config.targetInfo = adTargetInfo
tokenLoader.loadBidderToken(requestConfiguration: config) { ... }
|
|
SDK 8
|
let targeting = AdTargeting()
let request = BidderTokenRequest.banner(
size: adSize,
targeting: targeting,
parameters: ["key": "value"]
)
tokenLoader.loadBidderToken(request: request) { ... }
let interstitialRequest = BidderTokenRequest.interstitial()
let rewardedRequest = BidderTokenRequest.rewarded()
let nativeRequest = BidderTokenRequest.native()
let appOpenRequest = BidderTokenRequest.appOpenAd()
|
|
SDK 7
|
YMABidderTokenRequestConfiguration *config =
[[YMABidderTokenRequestConfiguration alloc] initWithAdType:YMAAdTypeBanner];
config.bannerAdSize = adSize;
config.targetInfo = adTargetInfo;
[tokenLoader loadBidderTokenWithRequestConfiguration:config
completionHandler:^(NSString *token) { ... }];
|
|
SDK 8
|
YMAAdTargeting *targeting = [[YMAAdTargeting alloc] initWithAge:nil
gender:nil
location:nil
contextQuery:nil
contextTags:nil];
YMABidderTokenRequest *request = [YMABidderTokenRequest bannerWithSize:adSize
targeting:targeting
parameters:@{@"key": @"value"}];
[tokenLoader loadBidderTokenWithRequest:request
completionHandler:^(NSString *token) { ... }];
YMABidderTokenRequest *interstitialRequest = [YMABidderTokenRequest interstitial];
YMABidderTokenRequest *rewardedRequest = [YMABidderTokenRequest rewarded];
YMABidderTokenRequest *nativeRequest = [YMABidderTokenRequest native];
YMABidderTokenRequest *appOpenRequest = [YMABidderTokenRequest appOpenAd];
|
SwiftUI 集成
已支持通过 SwiftUI 集成。请参阅 iOS 文档菜单末尾的 SwiftUI 小节:
使用 AI 工具迁移
为简化从 SDK 7.x 迁移到 8.x,可使用带有现成迁移技能的 AI 助手。
如何使用
-
安装技能
迁移技能位于 GitHub Yandex Ads SDK iOS。
-
用于 Claude Desktop
将技能文件夹复制到代理的 skills 目录,例如:
cp -r Skills/migrate-yandex-ads-sdk-from-7-to-8 .claude/skills/
-
用于 Cursor IDE
将技能文件夹复制到项目中,并通过 @ 引用 SKILL.md 文件,例如:
@migrate-yandex-ads-sdk-from-7-to-8/SKILL.md
-
其他方式
可将 SKILL.md 及相关文件内容复制到与 AI 助手的对话中(但可能超出消息长度限制)。
-
使用提示词
安装技能后,在与 AI 助手的对话中使用以下提示词:
将我的项目从 Yandex Mobile Ads SDK 7.x 迁移到 8.x
请务必仔细审查 AI 生成的变更。
尽管技能有助于 AI 助手更可靠地完成任务,您仍应亲自检查并验证代理所做的全部修改。AI 助手可能出错,因此必须进行人工代码审查。
SKAdNetwork
已更新 SKAdNetwork 标识符列表,并新增用于自动更新该列表的工具。实现与使用方式请参阅 SKAdNetwork 小节。
环境要求
- Xcode:26.0 及以上
- AppMetricaCore:6.0.0 及以上
- AppMetricaLibraryAdapter:6.0.0 及以上
- AppMetricaAdSupport:6.0.0 及以上
- AppMetricaIDSync:6.0.0 及以上