类型 函数 返回值 字符串 修订 版本 2024.3703 关键词 广告, Appnext, createAd 另请参阅 appnext.loadAd() appnext.*
此函数用于创建具有特定类型和广告位 ID 的广告。如果具有相同类型和广告位 ID 的广告已存在,则不会重新创建。
appnext.createAd( adType, placementID [, configParams] )
字符串. 广告的类型。可能的值包括 "interstitial"
(插屏式广告), "fullscreen"
(全屏广告), 和 "rewarded"
(激励视频广告)。
字符串. 广告的广告位 ID。
表. 包含已创建广告的配置参数的 Lua 表 — 有关详细信息,请参阅下一节。
configParams
表包含广告的配置参数。
Categories
— 以逗号分隔的 字符串 列表,用于设置首选广告类别。Postback
— 用户安装应用后将发布到您的服务器的回传参数(字符串)。请确保对值进行编码。ButtonText
— 字符串,指示安装按钮的文本。默认为 "安装"
。ButtonColor
— 字符串,指示安装按钮的颜色,为#
开头的十六进制颜色。PreferredOrientation
— 字符串,设置首选方向(假设应用程序支持横向和纵向)。可能的值为 "automatic"
(自动), "landscape"
(横向), 或 "portrait"
(纵向)。默认为 "automatic"
。BackButtonCanClose
— 仅适用于 Android;布尔值,指示“返回”键是否可以关闭广告。默认为 false
。Mute
— 布尔值,可以将广告中播放的视频静音。默认为 false
。ProgressType
— 字符串,设置或隐藏进度类型。可能的值为 "clock"
(时钟), "bar"
(进度条), "none"
(无), 或 "default"
(默认)。默认为 "clock"
。ProgressColor
— 字符串,指示进度条和时钟的颜色,为#
开头的十六进制颜色。VideoLength
— 字符串,指示视频长度为 15 或 30 秒。可能的值为 "15"
, "30"
, 或 "default"
(默认)。默认为 "15"
。ShowClose
— 布尔值,可以显示或隐藏“关闭”按钮。CloseDelay
— 如果显示“关闭”按钮,则将其外观延迟设定的 数字 值(以秒为单位)。local appnext = require( "plugin.appnext" ) local function adListener( event ) print( "Received " .. event.event .. " for " .. event.adKey .. " with message: " .. event.message ) end -- Initialize the Appnext plugin appnext.init( adListener ) -- Create your ads local interstitialPlacementID local fullscreenPlacementID local rewardedPlacementID local platform = system.getInfo( "platformName" ) if ( platform == "iPhone OS" ) then interstitialPlacementID = "YOUR_IOS_INTERSTITIAL_PLACEMENT_ID" fullscreenPlacementID = "YOUR_IOS_FULLSCREEN_PLACEMENT_ID" rewardedPlacementID = "YOUR_IOS_REWARDED_PLACEMENT_ID" elseif ( platform == "Android" ) then interstitialPlacementID = "YOUR_ANDROID_INTERSTITIAL_PLACEMENT_ID" fullscreenPlacementID = "YOUR_ANDROID_FULLSCREEN_PLACEMENT_ID" rewardedPlacementID = "YOUR_ANDROID_REWARDED_PLACEMENT_ID" end local interstitialConfig = { SkipText = "Close Ad", CreativeType = "video" } local videoConfig = { ShowClose = true, CloseDelay = 5.5 } local interstitialAdKey = appnext.createAd( "interstitial", interstitialPlacementID, interstitialConfig ) local fullscreenAdKey = appnext.createAd( "fullscreen", fullscreenPlacementID, videoConfig ) local rewardedAdKey = appnext.createAd( "rewarded", rewardedPlacementID )