文档

​
​

Development

User Acquisition

Monetization

工业

Unity Ads 变现

Unity Ads Android SDK

Unity Ads iOS SDK

Unity Ads SDK

Unity Ads 变现

Unity Ads Monetization
​
​
iOS 开发者指南
  • iOS SDK 概述
  • 集成要求
  • 安装适用于 iOS 的 Unity Ads SDK
  • 在 iOS 中初始化 SDK
  • 在 iOS 中实现插页式广告
  • 在 iOS 中实现奖励广告
  • 在 iOS 中实现横幅广告
iOS 14 集成
  • iOS 14 技术集成
  • 更新适用于 iOS 14 的 Unity Ads SDK
  • 安装 iOS 14 支持包
  • 配置广告平台 ID
  • 应用追踪透明度的合规性
iOS SDK API 参考
  • Unity Ads for iOS API 参考 (Objective-C)
  1. 实现游戏增长
  2. Unity Ads
  3. 适用于 iOS 开发者的 Unity Ads SDK 集成指南

在 iOS 中实现横幅广告

在 iOS 应用中实现横幅广告。在 View 层级视图中创建和显示横幅广告视图对象,并使用委托来管理广告事件。
阅读时间4 分钟
最后更新于 3 天前

重要
app-ads.txt 是一个 IAB 倡议文件,旨在打击欺诈,建立透明的广告生态系统。请务必按照要求实现 app-ads.txt。否则,横幅广告需求可能会显著下降。
横幅广告需要特定类型的专用横幅广告单元。
您可以将横幅广告视图对象放入 View 层级视图中,就像放置任何其他视图一样。这样就可以自定义每个横幅广告实例的位置,或显示多个横幅广告。
注意
如 Apple 指南中所述,横幅广告的内容不会在安全区域之外呈现。

脚本实现

将您的横幅广告代码添加到
ViewController
实现 (
.m
) 中。以下脚本示例是用于在屏幕上展示两个横幅广告的示例实现方案。如需了解引用的类的更多信息,请参阅
UADSBannerView
API 部分。

实现 MREC 横幅广告格式

注意
在展示横幅广告之前必须初始化 Unity Ads。
要在应用中显示中等矩形 (MREC) 大小的广告格式,请确保使用适当的尺寸,例如 300x250、300x300 或 450x450。如果使用的是 300x250 的 MREC 横幅广告,将它替换为以下示例代码:
CGSizeMake(320, 50)
调整后的尺寸:
CGSizeMake(300, 250)

横幅广告示例

@interface ViewController () <UADSBannerViewDelegate>​​// This is the Ad Unit or Placement that will display banner ads: @property (strong) NSString* placementId;// This banner view object will be placed at the top of the screen: @property (strong, nonatomic) UADSBannerView *topBannerView;// This banner view object will be placed at the bottom of the screen: @property (strong, nonatomic) UADSBannerView *bottomBannerView;​​@end​​@implementation ViewController​​- (void)viewDidLoad { [super viewDidLoad]; self.placementId = @"banner"; [UnityAds initialize: @"1234567" testMode: YES initializationDelegate: self];}​​// Example method for creating and loading the top banner view object: - (void)loadTopBanner{ // Instantiate a banner view object with the Ad Unit ID and size: self.topBannerView = [[UADSBannerView alloc] initWithPlacementId:_placementId size:CGSizeMake(320, 50)]; // Set the banner delegate for event callbacks: self.topBannerView.delegate = self; // Add the banner view object to the view hierarchy: [self addBannerViewToTopView:self.topBannerView]; // 将广告内容加载到横幅视图对象: [_topBannerView load];}​​// Example method for creating and loading the bottom banner view object: - (void)loadBottomBanner{ self.bottomBannerView = [[UADSBannerView alloc] initWithPlacementId:_placementId size:CGSizeMake(320, 50)]; self.bottomBannerView.delegate = self; [self addBannerViewToBottomView:self.bottomBannerView]; [_bottomBannerView load];}​​// Example method for discarding the top banner view object (for example, if there's no fill): - (void)unLoadTopBanner{ // Remove the banner view object from the view hierarchy: [self.topBannerView removeFromSuperview]; // Set it to nil: _topBannerView = nil;}​​// Example method for discarding the bottom banner view object: - (void)unLoadBottomBanner{ [self.bottomBannerView removeFromSuperview]; _bottomBannerView = nil;}​​​// Example method for placing the top banner view object: - (void)addBannerViewToTopView:(UIView *)bannerView { bannerView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:bannerView]; [self.view addConstraints:@[ [NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1 constant:0], [NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0] ]];}​// Example method for placing the bottom banner view object:- (void)addBannerViewToBottomView: (UIView *)bannerView { bannerView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:bannerView]; [self.view addConstraints:@[ [NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1 constant:0], [NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0] ]];}​// Implement the delegate methods:#pragma mark :UADSBannerViewDelegate- (void)bannerViewDidLoad:(UADSBannerView *)bannerView { // Called when the banner view object finishes loading an ad. NSLog(@"Banner loaded for Ad Unit or Placement: %@", bannerView.placementId);}- (void)bannerViewDidClick:(UADSBannerView *)bannerView { // Called when the banner is clicked. NSLog(@"Banner was clicked for Ad Unit or Placement: %@", bannerView.placementId);}- (void)bannerViewDidLeaveApplication:(UADSBannerView *)bannerView { // Called when the banner links out of the application.}- (void)bannerViewDidError:(UADSBannerView *)bannerView error:(UADSBannerError *)error{ // Called when an error occurs showing the banner view object. NSLog(@"Banner encountered an error for Ad Unit or Placement: %@ with error message %@", bannerView.placementId, [error localizedDescription]); // Note that the UADSBannerError can indicate no fill (refer to the API documentation).}@end
后续步骤:查看变现策略指南并测试您的实现。

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • 脚本实现

      • 实现 MREC 横幅广告格式

        • 横幅广告示例


报告此页面的问题