文档

Unity Ads 变现


iOS API 参考 - Swift

iOS API 参考 - Objective-C

Unity Ads 变现


在 iOS 中实现插页式广告

在 iOS 应用中实现插页式广告。加载广告内容,通过 Objective-C 或 Swift 代码展示广告,并使用委托来处理广告事件。
阅读时间3 分钟最后更新于 1 个月前

插页式广告加载示例

使用
UADSLoadConfigurationBuilder
使用放置/位置 ID、聚合元数据和可选的广告标记来构建加载请求,然后将其通道给
UADSInterstitialAd.load()
。完成代码块在成功时接收加载的
UADSInterstitialAd
实例。保留它,因为稍后需要显示广告,或者在失败时显示报错对象。
如果在 SDK 加载广告后未在设定时间内显示广告,则广告服务到期。在加载的广告实例上分配
onAdExpired
来检测此情况。尝试
show()
过期的奖励广告会失败,这一点尤其重要,因为奖励广告服务通常会预先加载并保留,直到用户请求奖励。使用回调可清除存储的引用并发出新的
load()
调用,以便在需要时准备好新的广告。
@property(strong) UADSInterstitialAd *interstitialAd;UADSLoadConfigurationBuilder *builder = [[UADSLoadConfigurationBuilder alloc] initWithPlacementId:placementId];builder = [builder withMediationInfo:self.mediationInfo];builder = [builder withAdMarkup:bidResponse];[UADSInterstitialAd 加载:[构建器构建] 完成:^(UADSInterstitialAd *ad, id<UnityAdsError> 报错) { if (error) { NSLog(@"Failed: %ld %@", (long)error.code, error.message); } else { __weak typeof(self) weakSelf = self; ad.onAdExpired = ^(UnityAd *expiredAd) { weakSelf.interstitialAd = nil; // reload here }; }}];

插页式广告展示示例

对保留的
UADSInterstitialAd
实例调用
show()
,传递使用呈现视图控制器构建的
UADSShowConfiguration
和
UADSInterstitialShowDelegate
。委托为广告生命周期的每个阶段提供回调:广告显示时的
showDidStart
、用户与其交互时的
showDidClick
、关闭时的
showDidComplete
以及发生报错时的
showDidFail
。
@interface MyDelegate:NSObject <UADSInterstitialShowDelegate>@end@implementation MyDelegate- (void)showDidStart:(UADSInterstitialAd *)unityAd { }}- (void)showDidClick:(UADSInterstitialAd *)unityAd { }}- (void)showDidComplete:(UADSInterstitialAd *)unityAd with:(UADSShowFinishState)finishState {}- (void)showDidFail:(UADSInterstitialAd *)unityAd 报错:(id<UnityAdsError>)报错 {}@endUADSShowConfigurationBuilder *builder =[[UADSShowConfigurationBuilder alloc] init];builder = [builder withViewController:viewController];[self.interstitialAd show:[builder build] delegate:delegate];
后续步骤:请参阅关于在 iOS 中实现奖励广告的文档以改进您的实现。