appnext.adIsLoaded()

类型 函数
返回值 布尔值
修订版 发行版本 2024.3703
关键词 广告、广告宣传、Appnext、adIsLoaded
请参阅 appnext.createAd()
appnext.loadAd()
appnext.showAd()
appnext.*

概览

此函数用于检查之前使用 appnext.createAd() 创建并使用 appnext.loadAd() 加载的广告是否已加载。

语法

appnext.adIsLoaded( adKey )
adKey (必需)

String. 之前从 appnext.createAd() 收到的广告密钥。

示例

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 interstitialAdKey = appnext.createAd( "interstitial", interstitialPlacementID )
local fullscreenAdKey = appnext.createAd( "fullscreen", fullscreenPlacementID )
local rewardedAdKey = appnext.createAd( "rewarded", rewardedPlacementID )
 
-- Load your ad before showing
appnext.loadAd( interstitialAdKey )
 
-- Sometime later, when you want to show the interstitial ad
if ( appnext.adIsLoaded( interstitialAdKey ) ) then
    appnext.showAd( interstitialAdKey )
end