ads.height() is not working

I called it right after ads.show(), I called it at the ad listener, and I even tried to call it after a 5 second delay. I couldnt make it work. Even the ad does show correctly, for all of these cases ads.height() returns the value 0.

How can I make it work? Can you post a working code?

http://docs.coronalabs.com/plugin/ads-admob-v2/height.html

It has to be part of the .init

local ads = require "ads" local function adListener( event ) local theHeight = ads.height() end ads.init(provider, id, adListener )

Yosu thats what İ did. Is it it because imusing corona version 2014.2393?

Hi @gainsempire,

I believe the documentation is correct that this should be called after ads.show(), not in the listener for ads.init(). Can you please post your code so we can inspect? Also, I assume you’ve correctly declared usage of the AdMob V2 plugin, not the original AdMob plugin?

Thanks,

Brent

Hi Brent,

I called it right after ads.show() and just to be sure I called it right after ads.show() with a 5 second delay. Both of the times the function returned the value 0 even though the admob banner was showing.

Here is a part of my build.settings

android = {    usesPermissions =    {       "android.permission.INTERNET",       "android.permission.ACCESS\_NETWORK\_STATE",          }, }, plugins =     {     ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },

From the scenw I show ads

ads.init( "admob", "ca-app-pub-#", adMobListener )

I call ads.show inside of scene:create( event )

ads.show( “banner”, { x=0, y=100000} ) --to make it appear at the bottomof the screen. And it does appear.

ads.height()

Hi @gainsempire,

As a test, can you just do this action in a base main.lua file, instead of within a Composer scene event? I’m curious to see if the result varies at all.

Brent

Strange things are happening. I made a test app. I just removed my app-unit -id from the file. I took a screenshot.

NHVuesB.png

I dont understand why im seeing this number.

Here are my files.

build.settings

-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "portrait", supported = { "portrait", } }, iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend } }, -- Android permissions androidPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", }, plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, }

main.lua

local ads = require( "ads" ) local widget = require("widget"); a = display.newText("TESTING", 100, 100, "Myriad Pro Light", 25) a:setFillColor(255,255,255) a.anchorX = 1 a.anchorY = 0.5 local function adMobListener( event ) a.text = "height not working listener working" a.text = "Height-"..ads.height() if ( event.isError ) then a.text = "Error" else a.text = "Success".."ad height"..ads.height() end return true end ads.init( "admob", "ca-app-pub-#", adMobListener ) ads:setCurrentProvider( "admob" ) ads.show( "banner", { x=0, y=0 } )

You’re trying to check the height from inside the init() listener. Why?

Ok I tried it right after ads.show and it works. My question is will it still work if the ad is displayed some seconds later ads.show was called?

Because I get a ads.height() is nil error when my scene takes some seconds to load.

Hi @gainsempire,

May I ask why you need to show an ad at one point then get its height later? Why can’t you just store the height of the current ad in a variable and then access that variable later? Or show the ad after the scene loads, which is probably a better approach anyway?

What’s up with ‘ads:setCurrentProvider( “admob” )’  ?

Anyway, i do check for nil value and don’t do anything if so.

Here is my whole code. Works for me :

Main part is below. Attached file is the whole code with my own codings.

local showAd local ads = require "ads" local function adListener( event ) if event.isError then else local height = ads.height() end end function showAd( adType, options ) ads.show( adType, { x=adXPos, y=adYPos, interval = 10, testMode = sg\_adMob.isTestMode } ) end ads.init( sg\_adMob.provider, sg\_adMob.id, adListener )

It has to be part of the .init

local ads = require "ads" local function adListener( event ) local theHeight = ads.height() end ads.init(provider, id, adListener )

Yosu thats what İ did. Is it it because imusing corona version 2014.2393?

Hi @gainsempire,

I believe the documentation is correct that this should be called after ads.show(), not in the listener for ads.init(). Can you please post your code so we can inspect? Also, I assume you’ve correctly declared usage of the AdMob V2 plugin, not the original AdMob plugin?

Thanks,

Brent

Hi Brent,

I called it right after ads.show() and just to be sure I called it right after ads.show() with a 5 second delay. Both of the times the function returned the value 0 even though the admob banner was showing.

Here is a part of my build.settings

android = {    usesPermissions =    {       "android.permission.INTERNET",       "android.permission.ACCESS\_NETWORK\_STATE",          }, }, plugins =     {     ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },

From the scenw I show ads

ads.init( "admob", "ca-app-pub-#", adMobListener )

I call ads.show inside of scene:create( event )

ads.show( “banner”, { x=0, y=100000} ) --to make it appear at the bottomof the screen. And it does appear.

ads.height()

Hi @gainsempire,

As a test, can you just do this action in a base main.lua file, instead of within a Composer scene event? I’m curious to see if the result varies at all.

Brent

Strange things are happening. I made a test app. I just removed my app-unit -id from the file. I took a screenshot.

NHVuesB.png

I dont understand why im seeing this number.

Here are my files.

build.settings

-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "portrait", supported = { "portrait", } }, iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend } }, -- Android permissions androidPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", }, plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, }

main.lua

local ads = require( "ads" ) local widget = require("widget"); a = display.newText("TESTING", 100, 100, "Myriad Pro Light", 25) a:setFillColor(255,255,255) a.anchorX = 1 a.anchorY = 0.5 local function adMobListener( event ) a.text = "height not working listener working" a.text = "Height-"..ads.height() if ( event.isError ) then a.text = "Error" else a.text = "Success".."ad height"..ads.height() end return true end ads.init( "admob", "ca-app-pub-#", adMobListener ) ads:setCurrentProvider( "admob" ) ads.show( "banner", { x=0, y=0 } )

You’re trying to check the height from inside the init() listener. Why?

Ok I tried it right after ads.show and it works. My question is will it still work if the ad is displayed some seconds later ads.show was called?