集成Banner广告

Vungle Banner目前处于测试阶段。请直接与您的客户经理联系以获取访问权限,以确保成功启动。

从Vungle SDK v.6.5.1开始,我们支持横幅广告。这种广告格式不需要全屏显示;而是由发布商确定广告容器在其应用中的位置。但是,横幅容器的尺寸必须为320x50、300x50或728x90(对于平板电脑)。您可以在屏幕上的任何位置设置横幅广告,并且用户可以在播放广告的同时继续使用该应用。可以在VungleSDK.h文件中找到列出不同横幅大小的枚举(也在下表中进行描述)。

Banner Sizes Dimension
VungleAdSizeBanner 320 x 50
VungleAdSizeBannerShort 300 x 50
VungleAdSizeBannerLeaderboard 728 x 90

横幅广告的展示位置类型在Vungle仪表板中必须具有“横幅”类型。请随时与您的客户经理联系以启用横幅在仪表板上的放置。

步骤1. 完成基本集成

集成Banner,请先查看文档basic integration

步骤2. Load,Display和Close广告

加载横幅广告

加载横幅广告的工作方式与其他广告格式不同。使用以下API加载横幅广告。您必须指定要加载的横幅的大小,SDK会按照在仪表板上配置的时间间隔自动刷新横幅。请参阅上表以获取装入调用所需的枚举值。

函数概览:

/**
 * (Overloaded method)
 * Prepares a placement when you know that you will want
 * to show an ad experience tied to a specific placementID.
 * @param placementID the specific ID of the placement you would like to present at some point soon
 * @param size the VungleAdSize (enum) you would like to request (only for banner ad type at the moment)
 * @return NO if something goes immediately wrong with loading, YES otherwise
 */
- (BOOL)loadPlacementWithID:(NSString *)placementID withSize:(VungleAdSize)size error:(NSError **)error;

示例代码:

NSError* error;
VungleSDK* sdk = [VungleSDK sharedSDK];
if (![sdk loadPlacementWithID:@"Your_placement_ID_Here" withSize:BANNER_ENUM error:&error]) {
if (error) {
NSLog(@"Error occurred when loading placement: %@", error);
}
}

您还可以通过调用以下API来检查横幅广告的可用性:

函数概览:

/**
* (Overloaded method)
 * Returns `YES` when there is certainty that an ad will be able to play for a given placementID.
 * Returning `NO`.
 * @param size the VungleAdSize (enum) you would like to request (only for banner ad type at the moment)
 * @param placementID the specific ID of the placement you are trying to present
 */
- (BOOL)isAdCachedForPlacementID:(nonnull NSString *)placementID withSize:(VungleAdSize)size;

示例代码:

if([sdk isAdCachedForPlacementID:@"Your_placement_ID_Here" withSize:BANNER_ENUM]){
//Ad is cached successfully
}

检查展示位置的广告可用性

当 SDK 完成广告位置的广告缓存后,会调用以下回调方法:

- (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable placementID:(nullable NSString *)placementID error:(nullable NSError *)error;

示例代码:

Objective-CSwift
- (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable placementID:(NSString *)placementID error:(nullable NSError *)error {
    if([placementID isEqualToString:@"Your_placement_ID_Here"]) {
        self.playButtonPlacement1.enabled = isAdPlayable;
    }
}

注意:对于缓存优化的展示位置,仅当广告可用时才调用此回调方法。 SDK将继续为这些展示位置请求广告。对于所有其他展示位置,在“加载失败”的情况下调用此回调方法(在这种情况下, isAdPlayable返回“ NO”)。

您还可以通过以下属性来检查广告位置的广告可用性:

- (BOOL)isAdCachedForPlacementID:(nonnull NSString *)placementID;

显示横幅广告

您必须首先为横幅广告创建一个容器。此容器是一个UIView ,大小为300×250,320x50或728x90(仅适用于iPad)。您可以将此UIView放在屏幕上的任何位置。
然后,您必须调用addAdViewToView函数将容器与横幅广告相关联。

函数概览:

/**
 * Pass in an UIView which acts as a container for the ad experience. This view container may be placed in random positions.
 * @note This method should only be called using placements that have the `mrec` template type. ALSO, for the
 *`mrec` template type, note that the UIView must have a width of 300 and a height of 250. If the view is provided without
 * these dimensions, an error message will be returned and the ad will not be shown.
 * @param publisherView container view in which an ad will be displayed
 * @param options A reference to an instance of NSDictionary with customized ad playback options
 * @param placementID The placement defined on the Vungle dashboard
 * @param error An optional double reference to an NSError. In case this method returns `NO` it will be non-nil
 * @return YES/NO in case of success/error while presenting an AdUnit
 */
- (BOOL)addAdViewToView:(UIView *)publisherView withOptions:(nullable NSDictionary *)options placementID:(nullable NSString *)placementID error:(NSError *__autoreleasing _Nullable *_Nullable)error;

示例代码:

NSError *error;
NSDictionary *options = @{};
VungleSDK* sdk = [VungleSDK sharedSDK];
if (![sdk addAdViewToView:_bannerViewArea withOptions:options placementID:@"Your_placement_ID_Here" error:&error]) {
if (error)
{
NSLog(@"Error encountered while playing an ad: %@", error);
}
}

关闭横幅广告

调用finishedDisplayingAd函数以关闭横幅广告。请注意,此功能不接受展示位置;它只会关闭当前正在播放的任何横幅广告。根据您的实现,您可能需要进行一些清理(例如从其父视图中删除横幅容器UIView等)。

函数概览:

As of 6.7.0Deprecated
- (void)finishDisplayingAd:(NSString*)placementId;

示例代码:

VungleSDK* sdk = [VungleSDK sharedSDK];
[sdk finishedDisplayingAd:@"BANNER_PLACEMENTID_HERE"];

步骤3. 配置Banner Ads (Optional)

静音选项

Vungle SDK提供静音设置。您可以在调用playAd()方法时,传入静音设置。

示例代码:

Objective-CSwift
VungleSDK* sdk = [VungleSDK sharedSDK];
self.sdk.muted = true;

注意:此选项仅适用于Vungle SDK 6.3.1及更低版本的标准广告类型。动态模板广告的静音选项可在仪表板上进行配置。从Vungle SDK v6.3.2开始,Vungle将尊重所有广告的SDK端静音设置。

传递Mediation Ordinal

如果您从Vungle收到顺序数据报告,请使用此字段传递中介顺序。这是一个整数,指示此广告在游戏会话中的显示顺序(例如,如果已经在该会话中显示了两个广告,然后将来自Vungle的该广告显示为第三,则传递“ 3”)。 在此处阅读有关序数数据的更多信息。

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

这篇文章有帮助吗?