No problems, i understand.
So, i tested the example projec t on my phone and it works perfectly.
This is the script i must use to show a banner ?
local dirtylarry = require "dirtylarry/dirtylarry"
local MAX_LOG_LINES = 10
--log logic
local gprint = print
local log = {}
local text = ""
_G.print = function(...)
gprint(...)
local args = {...}
local num = #log+1
log[num] = "--"
for k, v in pairs(args) do
log[num] = log[num] .. tostring(v) .. " "
end
log[num] = log[num] .. "\n"
text = ""
if num > MAX_LOG_LINES then
table.remove(log, 1)
end
for k, v in pairs(log) do
text = text .. v
end
end
function update()
gui.set_text(gui.get_node("console"), text)
end
-- end log logic
local function update_ui(self)
gui.set_enabled(gui.get_node("inited"), self.initialized)
gui.set_enabled(gui.get_node("initialization_box"), not self.initialized)
if self.ad_type then
gui.set_enabled(gui.get_node("load_ad/larrybutton"), true)
gui.set_enabled(gui.get_node("hide_ad/larrybutton"), false)
gui.set_enabled(gui.get_node("destroy_ad/larrybutton"), false)
if self.ad_type == admob.MSG_INTERSTITIAL then
gui.set_enabled(gui.get_node("show_ad/larrybutton"), admob.is_interstitial_loaded())
elseif self.ad_type == admob.MSG_REWARDED then
gui.set_enabled(gui.get_node("show_ad/larrybutton"), admob.is_rewarded_loaded())
elseif self.ad_type == admob.MSG_BANNER then
local is_banner_loaded = admob.is_banner_loaded()
gui.set_enabled(gui.get_node("show_ad/larrybutton"), is_banner_loaded)
gui.set_enabled(gui.get_node("hide_ad/larrybutton"), is_banner_loaded)
gui.set_enabled(gui.get_node("destroy_ad/larrybutton"), is_banner_loaded)
end
else
gui.set_enabled(gui.get_node("load_ad/larrybutton"), false)
gui.set_enabled(gui.get_node("show_ad/larrybutton"), false)
gui.set_enabled(gui.get_node("hide_ad/larrybutton"), false)
gui.set_enabled(gui.get_node("destroy_ad/larrybutton"), false)
end
end
local function set_block_height(height)
-- use banner height in gui
local screen_width, screen_height = window.get_size()
local settings_height = tonumber(sys.get_config("display.height"))
local mult = screen_height/settings_height
local height_b_node = gui.get_node("height_b")
local size = gui.get_size(height_b_node)
size.y = height/mult
gui.set_size(height_b_node, size)
end
local function admob_callback(self, message_id, message)
if message_id == admob.MSG_INITIALIZATION then
self.initialized = true
if message.event == admob.EVENT_COMPLETE then
print("EVENT_COMPLETE: Initialization complete")
elseif message.event == admob.EVENT_JSON_ERROR then
print("EVENT_JSON_ERROR: Internal NE json error "..message.error)
end
elseif message_id == admob.MSG_IDFA then
if message.event == admob.EVENT_STATUS_AUTORIZED then
print("EVENT_STATUS_AUTORIZED: ATTrackingManagerAuthorizationStatusAuthorized")
elseif message.event == admob.EVENT_STATUS_DENIED then
print("EVENT_STATUS_DENIED: ATTrackingManagerAuthorizationStatusDenied")
elseif message.event == admob.EVENT_STATUS_NOT_DETERMINED then
print("EVENT_STATUS_NOT_DETERMINED: ATTrackingManagerAuthorizationStatusNotDetermined")
elseif message.event == admob.EVENT_STATUS_RESTRICTED then
print("EVENT_STATUS_RESTRICTED: ATTrackingManagerAuthorizationStatusRestricted")
elseif message.event == admob.EVENT_NOT_SUPPORTED then
print("EVENT_NOT_SUPPORTED: IDFA request not supported on this platform or OS version")
end
elseif message_id == admob.MSG_INTERSTITIAL then
if message.event == admob.EVENT_CLOSED then
print("EVENT_CLOSED: Interstitial AD closed")
elseif message.event == admob.EVENT_FAILED_TO_SHOW then
print("EVENT_FAILED_TO_SHOW: Interstitial AD failed to show\nCode: "..message.code.."\nError: "..message.error)
elseif message.event == admob.EVENT_OPENING then
-- on android this event fire only when ADS activity closed =(
print("EVENT_OPENING: Interstitial AD is opening")
elseif message.event == admob.EVENT_FAILED_TO_LOAD then
print("EVENT_FAILED_TO_LOAD: Interstitial AD failed to load\nCode: "..message.code.."\nError: "..message.error)
elseif message.event == admob.EVENT_LOADED then
print("EVENT_LOADED: Interstitial AD loaded")
elseif message.event == admob.EVENT_NOT_LOADED then
print("EVENT_NOT_LOADED: can't call show_interstitial() before EVENT_LOADED\nError: "..message.error)
elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
print("EVENT_IMPRESSION_RECORDED: Interstitial did record impression")
elseif message.event == admob.EVENT_CLICKED then
print("EVENT_CLICKED: Interstitial clicked")
elseif message.event == admob.EVENT_JSON_ERROR then
print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
end
elseif message_id == admob.MSG_REWARDED then
if message.event == admob.EVENT_CLOSED then
print("EVENT_CLOSED: Rewarded AD closed")
elseif message.event == admob.EVENT_FAILED_TO_SHOW then
print("EVENT_FAILED_TO_SHOW: Rewarded AD failed to show\nCode: "..message.code.."\nError: "..message.error)
elseif message.event == admob.EVENT_OPENING then
-- on android this event fire only when ADS activity closed =(
print("EVENT_OPENING: Rewarded AD is opening")
elseif message.event == admob.EVENT_FAILED_TO_LOAD then
print("EVENT_FAILED_TO_LOAD: Rewarded AD failed to load\nCode: "..message.code.."\nError: "..message.error)
elseif message.event == admob.EVENT_LOADED then
print("EVENT_LOADED: Rewarded AD loaded")
elseif message.event == admob.EVENT_NOT_LOADED then
print("EVENT_NOT_LOADED: can't call show_rewarded() before EVENT_LOADED\nError: "..message.error)
elseif message.event == admob.EVENT_EARNED_REWARD then
print("EVENT_EARNED_REWARD: Reward: " .. tostring(message.amount) .. " " .. tostring(message.type))
elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
print("EVENT_IMPRESSION_RECORDED: Rewarded did record impression")
elseif message.event == admob.EVENT_CLICKED then
print("EVENT_CLICKED: Rewarded clicked")
elseif message.event == admob.EVENT_JSON_ERROR then
print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
end
elseif message_id == admob.MSG_BANNER then
if message.event == admob.EVENT_LOADED then
print("EVENT_LOADED: Banner AD loaded. Height: "..message.height.."px Width: "..message.width.."px")
set_block_height(message.height)
elseif message.event == admob.EVENT_OPENING then
print("EVENT_OPENING: Banner AD is opening")
elseif message.event == admob.EVENT_FAILED_TO_LOAD then
print("EVENT_FAILED_TO_LOAD: Banner AD failed to load\nCode: "..message.code.."\nError: "..message.error)
elseif message.event == admob.EVENT_CLICKED then
print("EVENT_CLICKED: Banner AD clicked")
elseif message.event == admob.EVENT_CLOSED then
print("EVENT_CLOSED: Banner AD closed")
elseif message.event == admob.EVENT_DESTROYED then
print("EVENT_DESTROYED: Banner AD destroyed")
elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
print("EVENT_IMPRESSION_RECORDED: Banner did record impression")
elseif message.event == admob.EVENT_JSON_ERROR then
print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
end
end
update_ui(self)
end
function init(self)
msg.post(".", "acquire_input_focus")
local engine_info = sys.get_engine_info()
self.is_debug = engine_info.is_debug
if self.is_debug then
-- Always test ONLY with test ads units when you test integration!
if sys.get_sys_info().system_name == 'iPhone OS' then
-- https://developers.google.com/admob/ios/test-ads
self.banner_ad_unit = "ca-app-pub-3940256099942544/2934735716" -- test unit for banners
self.interstitial_ad_unit = "ca-app-pub-3940256099942544/4411468910" -- test unit for interstitial
self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/1712485313" -- test unit for rewarded
else --Android
-- From https://developers.google.com/admob/android/test-ads
self.banner_ad_unit = "ca-app-pub-3940256099942544/6300978111" -- test unit for banners
self.interstitial_ad_unit = "ca-app-pub-3940256099942544/1033173712" -- test unit for interstitial
self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/5224354917" -- test unit for rewarded
end
else
-- Always test ONLY with test ads units when you test integration!
-- !!! Replace this keys with your own keys :
-- https://developers.google.com/admob/android/quick-start#set_up_your_app_in_your_admob_account
if sys.get_sys_info().system_name == 'iPhone OS' then
self.banner_ad_unit = "ca-app-pub-3940256099942544/2934735716" -- !!! replace it with iOS banner unit
self.interstitial_ad_unit = "ca-app-pub-3940256099942544/4411468910" -- !!! replace it with iOS interstitial unit
self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/1712485313" -- !!! replace it with iOS rewarded unit
else --Android
self.banner_ad_unit = "ca-app-pub-3940256099942544/6300978111" -- !!! replace it with Android banner unit
self.interstitial_ad_unit = "ca-app-pub-3940256099942544/1033173712" -- !!! replace it with Android interstitial unit
self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/5224354917" -- !!! replace it with Android rewarded unit
end
end
self.show_pos = 1
self.banner_positions = {
"POS_BOTTOM_CENTER",
"POS_BOTTOM_LEFT",
"POS_BOTTOM_RIGHT",
"POS_NONE",
"POS_TOP_LEFT",
"POS_TOP_CENTER",
"POS_TOP_RIGHT",
"POS_CENTER"
}
-- `admob` works only on iOS and Android, make sure the extension is available
if admob then
-- !!! Set callback before initialization
admob.set_callback(admob_callback)
-- !!! Read documentation about privacy settings and use the following method if you need to apply it
-- https://developers.google.com/admob/ios/ccpa
-- https://developers.google.com/admob/android/ccpa
admob.set_privacy_settings(true)
end
update_ui(self)
end
function on_input(self, action_id, action)
if not admob then
return
end
local prev_type = self.ad_type
if gui.is_enabled(gui.get_node("initialization_box")) then
dirtylarry:button("initialization", action_id, action, function ()
print("admob.initialize()")
admob.initialize()
end)
dirtylarry:button("idfa", action_id, action, function ()
print("admob.request_idfa()")
admob.request_idfa()
end)
end
self.ad_type = dirtylarry:radio("ad_type_interstitial", action_id, action, admob.MSG_INTERSTITIAL, self.ad_type)
self.ad_type = dirtylarry:radio("ad_type_rewarded", action_id, action, admob.MSG_REWARDED, self.ad_type)
self.ad_type = dirtylarry:radio("ad_type_banner", action_id, action, admob.MSG_BANNER, self.ad_type)
if prev_type ~= self.ad_type then
update_ui(self)
end
if gui.is_enabled(gui.get_node("load_ad/larrybutton")) then
dirtylarry:button("load_ad", action_id, action, function ()
if self.ad_type == 0 then
elseif self.ad_type == admob.MSG_INTERSTITIAL then
print("admob.load_interstitial()")
admob.load_interstitial(self.interstitial_ad_unit)
elseif self.ad_type == admob.MSG_REWARDED then
print("admob.load_rewarded()")
admob.load_rewarded(self.rewardedvideo_ad_unit)
elseif self.ad_type == admob.MSG_BANNER then
print("admob.load_banner()")
-- 2nd parameter size, adaptive banner by default:
-- https://developers.google.com/admob/android/banner/adaptive?hl=en
admob.load_banner(self.banner_ad_unit)
end
end)
end
if gui.is_enabled(gui.get_node("show_ad/larrybutton")) then
dirtylarry:button("show_ad", action_id, action, function ()
if self.ad_type == 0 then
elseif self.ad_type == admob.MSG_INTERSTITIAL then
print("admob.show_interstitial()")
admob.show_interstitial()
elseif self.ad_type == admob.MSG_REWARDED then
print("admob.show_rewarded()")
admob.show_rewarded()
elseif self.ad_type == admob.MSG_BANNER then
print("admob.show_banner( admob."..self.banner_positions[self.show_pos]..")")
admob.show_banner(admob[self.banner_positions[self.show_pos]])
self.show_pos = self.show_pos + 1
if self.show_pos > #self.banner_positions then
self.show_pos = 1
end
end
end)
end
if gui.is_enabled(gui.get_node("hide_ad/larrybutton")) then
dirtylarry:button("hide_ad", action_id, action, function ()
if self.ad_type == admob.MSG_BANNER then
print("admob.hide_banner()")
admob.hide_banner()
end
end)
end
if gui.is_enabled(gui.get_node("destroy_ad/larrybutton")) then
dirtylarry:button("destroy_ad", action_id, action, function ()
if self.ad_type == admob.MSG_BANNER then
print("admob.destroy_banner()")
admob.destroy_banner()
end
end)
end
if gui.is_enabled(gui.get_node("show_ad_inspector/larrybutton")) then
dirtylarry:button("show_ad_inspector", action_id, action, function ()
print("admob.show_ad_inspector()")
admob.show_ad_inspector()
end)
end
end