appnext.loadAd()

Type Function
Return value none
Revision Release 2021.3646
Keywords ads, advertising, Appnext, loadAd
See also appnext.createAd()
appnext.adIsLoaded()
appnext.showAd()
appnext.*

Overview

This function is used to load and cache an ad previously created with appnext.createAd().

Note

Full-screen and rewarded ads must be loaded each time before showing. However, this call is not compulsory for interstitial ads.

Syntax

appnext.loadAd( adKey )
adKey (required)

String. The ad key returned from a previously-created ad.

Example

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 fullscreenPlacementID
local rewardedPlacementID

local platform = system.getInfo( "platformName" )
if ( platform == "iPhone OS" ) then
    fullscreenPlacementID = "YOUR_IOS_FULLSCREEN_PLACEMENT_ID"
    rewardedPlacementID = "YOUR_IOS_REWARDED_PLACEMENT_ID"
elseif ( platform == "Android" ) then
    fullscreenPlacementID = "YOUR_ANDROID_FULLSCREEN_PLACEMENT_ID"
    rewardedPlacementID = "YOUR_ANDROID_REWARDED_PLACEMENT_ID"
end

local fullscreenAdKey = appnext.createAd( "fullscreen", fullscreenPlacementID )
local rewardedAdKey = appnext.createAd( "rewarded", rewardedPlacementID )

-- Load your ads before showing
appnext.loadAd( fullscreenAdKey )
appnext.loadAd( rewardedAdKey )