Difference between revisions of "Iad.Banner.new"
Line 2: | Line 2: | ||
'''Available since:''' Gideros 2012.8<br/> | '''Available since:''' Gideros 2012.8<br/> | ||
=== Description === | === Description === | ||
− | <br /> | + | <translate><br /> |
− | Creates an | + | Creates an [[[iad.Banner]]] instance. If iAd framework is not available, this function gives an error.<br /> |
<br /> | <br /> | ||
The alignment and the orientation of the ad banner are defined by these 4 string constants:<br /> | The alignment and the orientation of the ad banner are defined by these 4 string constants:<br /> | ||
<br /> | <br /> | ||
<ul><br /> | <ul><br /> | ||
− | <li> | + | <li>[[[iad.Banner.TOP = "top"]]]</li><br /> |
− | <li> | + | <li>[[[iad.Banner.BOTTOM = "bottom"]]]</li><br /> |
− | <li> | + | <li>[[[iad.Banner.PORTRAIT = "portrait"]]]</li><br /> |
− | <li> | + | <li>[[[iad.Banner.LANDSCAPE = "landscape"]]]</li><br /> |
</ul><br /> | </ul><br /> | ||
<br /> | <br /> | ||
− | And | + | And [[[iad.Banner]]] class dispatches these 4 events:<br /> |
<br /> | <br /> | ||
<ul><br /> | <ul><br /> | ||
− | <li> | + | <li>[[[Event.BANNER_AD_LOADED = "bannerAdLoaded"]]]</li><br /> |
− | <li> | + | <li>[[[Event.BANNER_AD_FAILED = "bannerAdFailed"]]]</li><br /> |
− | <li> | + | <li>[[[Event.BANNER_ACTION_BEGIN = "bannerActionBegin"]]]</li><br /> |
− | <li> | + | <li>[[[Event.BANNER_ACTION_FINISHED = "bannerActionFinished"]]]</li><br /> |
</ul><br /> | </ul><br /> | ||
<br /> | <br /> | ||
Line 26: | Line 26: | ||
Apple also requires that the ad area be hidden when no ad is available to display. iAd module manages all this behavior for you automatically.<br /> | Apple also requires that the ad area be hidden when no ad is available to display. iAd module manages all this behavior for you automatically.<br /> | ||
<br /> | <br /> | ||
− | When an ad becomes available, it will be displayed on the screen, the event | + | When an ad becomes available, it will be displayed on the screen, the event [[[Event.BANNER_AD_LOADED]]] is dispatched when one is about to be displayed,<br /> |
− | or the event | + | or the event [[[Event.BANNER_AD_FAILED` is dispatched when the loading has failed. If the loading has failed, the fields `event.errorCode` and `event.errorDescription]]] <br /> |
contains information about the failure reason.<br /> | contains information about the failure reason.<br /> | ||
<br /> | <br /> | ||
− | When the user clicks on an ad, the event | + | When the user clicks on an ad, the event [[[Event.BANNER_ACTION_BEGIN]]] is dispatched. At this time, the user will either be taken out of your application <br /> |
− | to view the app store (in this case | + | to view the app store (in this case [[[event.willLeaveApplication]]] field will be true), or they will be presented with a fullscreen advertisement to interact with, <br /> |
− | and | + | and [[[event.willLeaveApplication` will be false. In the latter case, you may decide to pause the application until the event `Event.BANNER_ACTION_FINISHED]]] is dispatched. <br /> |
− | <br /> | + | <br /></translate> |
<source lang="lua"> | <source lang="lua"> | ||
iad.Banner.new(alignment,orientation) | iad.Banner.new(alignment,orientation) | ||
</source> | </source> | ||
=== Parameters === | === Parameters === | ||
− | '''alignment''': (string) whether you want ads to show top or bottom of the screen. It can be either iad.Banner.TOP or iad.Banner.BOTTOM. <br/> | + | '''alignment''': (string) <translate>whether you want ads to show top or bottom of the screen. It can be either iad.Banner.TOP or iad.Banner.BOTTOM.</translate> <br/> |
− | '''orientation''': (string) orientation of the banner. It can be either iad.Banner.PORTRAIT or iad.Banner.LANDSCAPE. <br/> | + | '''orientation''': (string) <translate>orientation of the banner. It can be either iad.Banner.PORTRAIT or iad.Banner.LANDSCAPE.</translate> <br/> |
=== Examples === | === Examples === | ||
'''Example'''<br/> | '''Example'''<br/> | ||
− | <source lang="lua">-- if the platform is iOS, load the iAd module | + | <source lang="lua">-- if the platform is iOS, load the iAd module |
− | if application:getDeviceInfo() == "iOS" then | + | if application:getDeviceInfo() == "iOS" then |
− | require "iad" | + | require "iad" |
− | end | + | end |
− | + | ||
− | -- 4 event listeners for debug print | + | -- 4 event listeners for debug print |
− | local function onBannerAdLoaded() | + | local function onBannerAdLoaded() |
− | print("banner ad loaded") | + | print("banner ad loaded") |
− | end | + | end |
− | + | ||
− | local function onBannerAdFailed(event) | + | local function onBannerAdFailed(event) |
− | print("banner ad failed", event.errorCode, event.errorDescription) | + | print("banner ad failed", event.errorCode, event.errorDescription) |
− | end | + | end |
− | + | ||
− | local function onBannerActionBegin(event) | + | local function onBannerActionBegin(event) |
− | print("banner action begin", event.willLeaveApplication) | + | print("banner action begin", event.willLeaveApplication) |
− | end | + | end |
− | + | ||
− | local function onBannerActionFinished() | + | local function onBannerActionFinished() |
− | print("banner action finished") | + | print("banner action finished") |
− | end | + | end |
− | + | ||
− | -- if iAd module is loaded and iAd framework is available, create an ad banner and then show it | + | -- if iAd module is loaded and iAd framework is available, create an ad banner and then show it |
− | local banner = nil | + | local banner = nil |
− | if iad and iad.isAvailable() then | + | if iad and iad.isAvailable() then |
− | banner = iad.Banner.new(iad.Banner.TOP, iad.Banner.PORTRAIT) | + | banner = iad.Banner.new(iad.Banner.TOP, iad.Banner.PORTRAIT) |
− | banner:addEventListener(Event.BANNER_AD_LOADED, onBannerAdLoaded) | + | banner:addEventListener(Event.BANNER_AD_LOADED, onBannerAdLoaded) |
− | banner:addEventListener(Event.BANNER_AD_FAILED, onBannerAdFailed) | + | banner:addEventListener(Event.BANNER_AD_FAILED, onBannerAdFailed) |
− | banner:addEventListener(Event.BANNER_ACTION_BEGIN, onBannerActionBegin) | + | banner:addEventListener(Event.BANNER_ACTION_BEGIN, onBannerActionBegin) |
− | banner:addEventListener(Event.BANNER_ACTION_FINISHED, onBannerActionFinished) | + | banner:addEventListener(Event.BANNER_ACTION_FINISHED, onBannerActionFinished) |
− | banner:show() -- show it because newly created banners are not visible by default | + | banner:show() -- show it because newly created banners are not visible by default |
− | end | + | end |
− | + | ||
− | -- show the banner (if it exists) | + | -- show the banner (if it exists) |
− | function showBanner() | + | function showBanner() |
− | if banner ~= nil then | + | if banner ~= nil then |
− | banner:show() | + | banner:show() |
− | end | + | end |
− | end | + | end |
− | + | ||
− | -- hide the banner (if it exists) | + | -- hide the banner (if it exists) |
− | function hideBanner() | + | function hideBanner() |
− | if banner ~= nil then | + | if banner ~= nil then |
− | banner:hide() | + | banner:hide() |
− | end | + | end |
− | end | + | end</source> |
Revision as of 13:35, 23 August 2018
Available since: Gideros 2012.8
Description
Creates an [[[iad.Banner]]] instance. If iAd framework is not available, this function gives an error.
The alignment and the orientation of the ad banner are defined by these 4 string constants:
<ul>
<li>[[[iad.Banner.TOP = "top"]]]</li>
<li>[[[iad.Banner.BOTTOM = "bottom"]]]</li>
<li>[[[iad.Banner.PORTRAIT = "portrait"]]]</li>
<li>[[[iad.Banner.LANDSCAPE = "landscape"]]]</li>
</ul>
And [[[iad.Banner]]] class dispatches these 4 events:
<ul>
<li>[[[Event.BANNER_AD_LOADED = "bannerAdLoaded"]]]</li>
<li>[[[Event.BANNER_AD_FAILED = "bannerAdFailed"]]]</li>
<li>[[[Event.BANNER_ACTION_BEGIN = "bannerActionBegin"]]]</li>
<li>[[[Event.BANNER_ACTION_FINISHED = "bannerActionFinished"]]]</li>
</ul>
When an ad banner is created, iAd will start requesting ads. Apple serves ads, and refreshes with new ads, on an automatic timer.
Apple also requires that the ad area be hidden when no ad is available to display. iAd module manages all this behavior for you automatically.
When an ad becomes available, it will be displayed on the screen, the event [[[Event.BANNER_AD_LOADED]]] is dispatched when one is about to be displayed,
or the event [[[Event.BANNER_AD_FAILED` is dispatched when the loading has failed. If the loading has failed, the fields `event.errorCode` and `event.errorDescription]]]
contains information about the failure reason.
When the user clicks on an ad, the event [[[Event.BANNER_ACTION_BEGIN]]] is dispatched. At this time, the user will either be taken out of your application
to view the app store (in this case [[[event.willLeaveApplication]]] field will be true), or they will be presented with a fullscreen advertisement to interact with,
and [[[event.willLeaveApplication` will be false. In the latter case, you may decide to pause the application until the event `Event.BANNER_ACTION_FINISHED]]] is dispatched.
iad.Banner.new(alignment,orientation)
Parameters
alignment: (string) whether you want ads to show top or bottom of the screen. It can be either iad.Banner.TOP or iad.Banner.BOTTOM.
orientation: (string) orientation of the banner. It can be either iad.Banner.PORTRAIT or iad.Banner.LANDSCAPE.
Examples
Example
-- if the platform is iOS, load the iAd module
if application:getDeviceInfo() == "iOS" then
require "iad"
end
-- 4 event listeners for debug print
local function onBannerAdLoaded()
print("banner ad loaded")
end
local function onBannerAdFailed(event)
print("banner ad failed", event.errorCode, event.errorDescription)
end
local function onBannerActionBegin(event)
print("banner action begin", event.willLeaveApplication)
end
local function onBannerActionFinished()
print("banner action finished")
end
-- if iAd module is loaded and iAd framework is available, create an ad banner and then show it
local banner = nil
if iad and iad.isAvailable() then
banner = iad.Banner.new(iad.Banner.TOP, iad.Banner.PORTRAIT)
banner:addEventListener(Event.BANNER_AD_LOADED, onBannerAdLoaded)
banner:addEventListener(Event.BANNER_AD_FAILED, onBannerAdFailed)
banner:addEventListener(Event.BANNER_ACTION_BEGIN, onBannerActionBegin)
banner:addEventListener(Event.BANNER_ACTION_FINISHED, onBannerActionFinished)
banner:show() -- show it because newly created banners are not visible by default
end
-- show the banner (if it exists)
function showBanner()
if banner ~= nil then
banner:show()
end
end
-- hide the banner (if it exists)
function hideBanner()
if banner ~= nil then
banner:hide()
end
end