InMobi hide

I implemented Inmobi correctly with banner and interstitial. I have a problem when i call inMobi.hide, after i can’t call another time the banner inMobi with inMobi.show.

If i close the sceneA with scene:destroy( event ) and then i load another time the sceneA the inMobi don’t display banner ads, why?

— In the main:

inMobi = require “plugin.inMobi”

accountID_inMobi = " … "

banner_inMobi = " … "

fullscreen_inMobi = " … "

local function adListener_inMobi(event)

   if ( event.phase == “init” ) then  

        – Load ad inMobi

        inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } )

    elseif ( event.phase == “failed” ) then

        …

    end

   end

inMobi.init( adListener_inMobi, { accountId=accountID_inMobi } )

— sceneA

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

      inMobi.show( banner_inMobi, { yAlign=“bottom” } )

    native.showAlert( “Load”, “Show InMobi” , { “OK”} )

   else

    native.showAlert( “inMobi”, "No-Load " , { “OK”} )

   end

end

— when close then scene 

inMobi.hide(banner_inMobi)

After the old banner is hidden, you must load a new banner before it can be shown.

I’ve already done this by rebooting inMobi.load, inMobil.init example :

— sceneA test1

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

     native.showAlert( “Load”, “Show InMobi” , { “OK”} )

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

   else

    native.showAlert( “No-Load”, “reLoad” , { “OK”} )

    inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } )

    inMobi.show( banner_inMobi, { yAlign=“bottom” } )

  end

end --showInMobi()

— sceneA test2

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

     native.showAlert( “Load”, “Show InMobi” , { “OK”} ) 

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

   else

      native.showAlert( “No-Load”, “reLoad” , { “OK”} )

      inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } 

      inMobi.show( banner_inMobi, { yAlign=“bottom” } )

  end

end --showInMobi()

— sceneA test2 

— show inMobi after 1,5 sec

local function reLoad()

   inMobi.show( banner_inMobi, { yAlign=“bottom” } )

end 

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

     native.showAlert( “Load”, “Show InMobi” , { “OK”} ) 

 

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

 

   else

      native.showAlert( “No-Load”, “reLoad” , { “OK”} )

 

      inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } 

 

      timer.performWithDelay( 1500, reLoad, 1 )

  end

end 

 

I tried invoking inMobi.init every time the sceneA was called up, but once I missed it inMobi.init I did not come back to call.

— sceneA test3

local inMobi = require “plugin.inMobi”

local accountID_inMobi = " … "

local banner_inMobi = " … "

local w_banner = 320

local h_banner = 50

local function adListener_inMobi(event)

if ( event.phase == “init” ) then  – Successful initialization

        – load ad inMobi

        inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } )

        native.showAlert( “Init”, “Initialize InMobi” , { “OK”} )

    elseif ( event.phase == “loaded”) then

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

     native.showAlert( “Show”, “Show InMobi” , { “OK”} )

    elseif ( event.phase == “failed” ) then

       local msg = event.type … " - " … event.isError … " - " … event.response

        native.showAlert( “InMobi Error”, msg, { “OK” } )

    end

end

inMobi.init( adListener_inMobi, { accountId=accountID_inMobi } )

You cannot call inmobi.show() directly after inmobi.load() as it takes time for the ad to load. How much time depends on many factors. Timers are not a reliable way to do this. The only reliable way is to wait for the “loaded” event phase in your event listener before calling inmobi.show().

Your third example will not work since inmobi.init() can only be called once within the lifetime of the app, which should be done in main.lua.

Also, keep in mind that showing banners during gameplay may affect your game’s framerate in a negative way. If your app has many animations you might see sluggish performance while banners are being shown. ymmv.

Thanks for your precious support, now it works!

After the old banner is hidden, you must load a new banner before it can be shown.

I’ve already done this by rebooting inMobi.load, inMobil.init example :

— sceneA test1

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

     native.showAlert( “Load”, “Show InMobi” , { “OK”} )

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

   else

    native.showAlert( “No-Load”, “reLoad” , { “OK”} )

    inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } )

    inMobi.show( banner_inMobi, { yAlign=“bottom” } )

  end

end --showInMobi()

— sceneA test2

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

     native.showAlert( “Load”, “Show InMobi” , { “OK”} ) 

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

   else

      native.showAlert( “No-Load”, “reLoad” , { “OK”} )

      inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } 

      inMobi.show( banner_inMobi, { yAlign=“bottom” } )

  end

end --showInMobi()

— sceneA test2 

— show inMobi after 1,5 sec

local function reLoad()

   inMobi.show( banner_inMobi, { yAlign=“bottom” } )

end 

local function showInMobi()

   if ( inMobi.isLoaded( banner_inMobi ) ) then

     native.showAlert( “Load”, “Show InMobi” , { “OK”} ) 

 

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

 

   else

      native.showAlert( “No-Load”, “reLoad” , { “OK”} )

 

      inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } 

 

      timer.performWithDelay( 1500, reLoad, 1 )

  end

end 

 

I tried invoking inMobi.init every time the sceneA was called up, but once I missed it inMobi.init I did not come back to call.

— sceneA test3

local inMobi = require “plugin.inMobi”

local accountID_inMobi = " … "

local banner_inMobi = " … "

local w_banner = 320

local h_banner = 50

local function adListener_inMobi(event)

if ( event.phase == “init” ) then  – Successful initialization

        – load ad inMobi

        inMobi.load( “banner”, banner_inMobi, { autoRefresh = true, width = w_banner, height = h_banner } )

        native.showAlert( “Init”, “Initialize InMobi” , { “OK”} )

    elseif ( event.phase == “loaded”) then

     inMobi.show( banner_inMobi, { yAlign=“bottom” } )

     native.showAlert( “Show”, “Show InMobi” , { “OK”} )

    elseif ( event.phase == “failed” ) then

       local msg = event.type … " - " … event.isError … " - " … event.response

        native.showAlert( “InMobi Error”, msg, { “OK” } )

    end

end

inMobi.init( adListener_inMobi, { accountId=accountID_inMobi } )

You cannot call inmobi.show() directly after inmobi.load() as it takes time for the ad to load. How much time depends on many factors. Timers are not a reliable way to do this. The only reliable way is to wait for the “loaded” event phase in your event listener before calling inmobi.show().

Your third example will not work since inmobi.init() can only be called once within the lifetime of the app, which should be done in main.lua.

Also, keep in mind that showing banners during gameplay may affect your game’s framerate in a negative way. If your app has many animations you might see sluggish performance while banners are being shown. ymmv.

Thanks for your precious support, now it works!