How to know ad "height" for iAd & adMob?

I want to put iAd & adMob ads together with my webView.

Since webView can only be on the top, therefore I need to calculate the exact height for the webView and leave the rest space for iAd/adMob ad.

For example, if the ad height is stored in “theAdHeight” in the code below, then I can create a webView like this (so the ad plus the webView can occupy the whole screen seamlessly)

local screenW, screenH = display.contentWidth, display.contentHeight local topY = display.screenOriginY local leftX = display.screenOriginX local trueW = rightX -leftX local trueH = bottomY - topY local theAdHeight = ???????? webView = native.newWebView(leftX, topY, trueW, trueH - theAdHeight)

In my config.lua, I use 320x480 letterbox. (Portrait mode)

So about the ad height, here are my experiment results:

(1) iAd + iPad 4, theAdHeight = 31 (how do I get this number? I don’t know, because I adjusted one pixel at a time to get this number)

(2) iAd + iPhone 5S, theAdHeight = 50  (I guessed right because the Apple doc says the ad is 320x50 points)

(3) adMob + iPad 4, theAdHeight = 42 (adjusted one pixel a time to get this number)

(4) adMob + iPhone 5S, theAdHeight = 50 (I guessed right because adMob doc says the ad is 320x50 for phones)

So my questions are:

a. how these two numbers 31 & 42 are calculated? anyone knows about the formula?

b. what about other devices? I don’t have iPhone 4/4S or iPad mini to test. How do I get the ad height for these devices?

c. are these ads fixed size? I saw somewhere saying that Corona use “smart banner” for admob… which means the height might not be fixed?

I have been testing iAd/adMob these three days. Since it cannot be tested in the simulator, it’s really time consuming. And the result is very unpredictable. (Besides this, there was another problem about placing the ad at the bottom of the screen that I have been asking in another thread. And this problem can extend to Android devices, but I want to forget Android devices for now, because it’s already too complicated with iOS devices)

I really hope someone who have been through this can share some thoughts. And, please Corona staff can help this regard. I feel so dizzy now.

I’ve found the answer for my questions. If anyone cares to know, just let me know, I will share with you. 

But the problem for placing admob at the bottom of the screen is still unsolved. I still cannot combine webView with admob in a single screen.

And I still have a question for Corona about ad height,

is it ever possible to return the height of the ad by plugin API?  For example, when using admob, it’s really hard to distinguish all the devices in order to know the “smart banner” height. If the API can return the height, thing will become much easier & perfect!

I’ve found the answer for my questions. If anyone cares to know, just let me know, I will share with you. 

But the problem for placing admob at the bottom of the screen is still unsolved. I still cannot combine webView with admob in a single screen.

And I still have a question for Corona about ad height,

is it ever possible to return the height of the ad by plugin API?  For example, when using admob, it’s really hard to distinguish all the devices in order to know the “smart banner” height. If the API can return the height, thing will become much easier & perfect!

We’ve released the new AdMob V2 plugin:   http://docs.coronalabs.com/plugin/ads-admob-v2/index.html

The only change you need to make to use it a change to your build.settings to use the new plugin.  There is a new API call (for adMob only) called ads.height() that can be called after a successful call to ad.show() to get the height of the ad.  No other features, changes, etc. are done with this new plugin, but it does address Google’s Aug 1 breaking change.

Rob

That sounds a good news.

But I just tried, it crashes by saying .height() is nil

I added this plugin as the document says:

settings = { plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, }

Is it correct? Why is it “google.play.services”? not admob-related?

Yes, Google is moving AdMob from their normal SDK to something that runs through Google Play.  Google may be moving other things there in the future.  I don’t know. 

Here is the docs on the height call:  http://docs.coronalabs.com/plugin/ads-admob-v2/height.html

Rob

Wow! Fresh off the wire!!! Great news. Thanks much.

<Off-Topic>

@Rob

What do I need to include in my project to use Admob V2 with Enterprise?

EDIT:

Created a new topic for this.

still can’t get it to work,

after adding the plugin

 ["plugin.google.play.services"] = { publisherId = "com.coronalabs" },

still have a runtime error:

attempt to call field 'height' (a nil value)

when calling ads.height()

Is that after a successful call to ads.show()?

I saw this line in the document

This will only return the correct result after calling ads.show().

I assume even if ad.show() is not successful (such as in a simulator), ads.height() shouldn’t crash even it returns incorrect result.

Since it crashes in a simulator, I am not testing this in actual devices.

Are you able to call ads.height() successfully without the crash I see?

I would suspect the call would be stubbed out in the simulator and shouldn’t crash.

We’ve released the new AdMob V2 plugin:   http://docs.coronalabs.com/plugin/ads-admob-v2/index.html

The only change you need to make to use it a change to your build.settings to use the new plugin.  There is a new API call (for adMob only) called ads.height() that can be called after a successful call to ad.show() to get the height of the ad.  No other features, changes, etc. are done with this new plugin, but it does address Google’s Aug 1 breaking change.

Rob

That sounds a good news.

But I just tried, it crashes by saying .height() is nil

I added this plugin as the document says:

settings = { plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, }

Is it correct? Why is it “google.play.services”? not admob-related?

Yes, Google is moving AdMob from their normal SDK to something that runs through Google Play.  Google may be moving other things there in the future.  I don’t know. 

Here is the docs on the height call:  http://docs.coronalabs.com/plugin/ads-admob-v2/height.html

Rob

Wow! Fresh off the wire!!! Great news. Thanks much.

<Off-Topic>

@Rob

What do I need to include in my project to use Admob V2 with Enterprise?

EDIT:

Created a new topic for this.

still can’t get it to work,

after adding the plugin

 ["plugin.google.play.services"] = { publisherId = "com.coronalabs" },

still have a runtime error:

attempt to call field 'height' (a nil value)

when calling ads.height()

Is that after a successful call to ads.show()?

I saw this line in the document

This will only return the correct result after calling ads.show().

I assume even if ad.show() is not successful (such as in a simulator), ads.height() shouldn’t crash even it returns incorrect result.

Since it crashes in a simulator, I am not testing this in actual devices.

Are you able to call ads.height() successfully without the crash I see?