Cannot align Facebook audience banner to the bottom

I’m Facing a problem with adView.Show(100); cannot align it to the bottom of the screen. I tries put inside UI Canves element align to the bottom and make adView.Show(0); but it’s align to the top of the screen not of the parent element. tried also adView.Show(canves.rect.height - 50); it’s appear on my phone screen good but on other screen totally in wrong position.

any help.

It’s a bit hard to tell just from what you posted; what is adView? What does Show() do exactly? Where does the banner appear now?

Hi Senshi,
sorry i thought it’s a popular ad network maybe anyone face the same issue but it appears known using it.
here is the full code that facebook provide. my problem with the show method that take float datatype for example this.adView.Show (0); mean the top of the screen i tried to but this object in Ui Panal that aligned to the bottom of the screen but no success. I keep trying with no success. Sometimes i could align it to the bottom of my phone but in different screen size it’s not at the bottom at all.

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using AudienceNetwork;

public class AdViewTest : MonoBehaviour {

    private AdView adView;

    void Awake () {
        // Create a banner's ad view with a unique placement ID (generate your own on the Facebook app settings).
        // Use different ID for each ad placement in your app.
        AdView adView = new AdView ("YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
        this.adView = adView;
        this.adView.Register (this.gameObject);

        // Set delegates to get notified on changes or when the user interacts with the ad.
        this.adView.AdViewDidLoad = (delegate() {
            Debug.Log("Ad view loaded.");
            this.adView.Show (100);
        });
        adView.AdViewDidFailWithError = (delegate(string error) {
            Debug.Log("Ad view failed to load with error: " + error);
        });
        adView.AdViewWillLogImpression = (delegate() {
            Debug.Log("Ad view logged impression.");
        });
        adView.AdViewDidClick = (delegate() {
            Debug.Log("Ad view clicked.");
        });

        // Initiate a request to load an ad.
        adView.LoadAd ();
    }

    void OnDestroy () {
        // Dispose of banner ad when the scene is destroyed
        if (this.adView) {
            this.adView.Dispose ();
        }
        Debug.Log("AdViewTest was destroyed!");
    }

    // Next button
    public void NextScene () {
        Application.LoadLevel ("NativeAdScene");
    }
}

for more info this is the link to facebook audience ad documentation for unity Add the SDK - Meta Audience Network - Documentation - Meta for Developers

Ah, ok! I’ve personally never used Audience Network, so I didn’t recognize it. The problem is I don’t know how adView.Show() works exactly; what the value means. However, I can make an educated guess, in that it’s an absolute size/ offset in pixels. Here’s something I came accross Googling, as well as another idea. Maybe try these and see how they behave?

//all assuming a 50px high ad
adView.Show(AdUtility.height() - 50);
adView.Show(Camera.main.pixelRect.height - 50);
adView.Show(canvas.rect.height - 50); //set "canvas" to your scene's canvas

If these don’t work, could you link me to an Audience Network API/ script reference please, so I can take a closer look?

As a by-the-way: this.adView = adView; is unnecessary. Since there’s no adView variable created in the local scope (Awake()), you can just use adView and it will refer to the one defined in your class.

Good luck!

Hi Senshi,
I really tried all those examples and I believe two of them are from my post on the stackoverflow but this is from 9 days ago i tried lot more from this time . this.adView = adView; this is included in their example and I don’t really know why.
you can find their sdk with a simple example in the following link

inside the zip file you will find a file named “AudienceNetwork.unitypackage”.

did you fix it?

Hi, I’m terribly sorry, but I’ve been busy lately and haven’t had a chance to look at it, and I’m not sure when I will. I’ll keep an eye on this post though when I get some time and motivation. Hoping someone else will see this topic too now.

Here is a fix after two days of debugging, it’s about logical resolution being different for iOS when using Screen.Height
And AdUtility.height() is broken for android.

#if UNITY_IOS
m_AdView.Show(AdUtility.height() - 50);
#elif UNITY_ANDROID
m_AdView.Show(Screen.height - 50);
#endif

1 Like

Hello, I found an error in code at AudienceNetwork/Library/AdUtility.cs. Change:

public override double height (){
       return this.convert (this.deviceWidth ());
}

change to:

public override double height (){
       return this.convert (this.deviceHeight ());
}

And u can show banner at bottom with code:

       this.adView.Show(AudienceNetwork.Utility.AdUtility.height() - 50); // AdSize.BANNER_HEIGHT_50

However some Android devices method AdUtility.height() wrong size, instead u can use Screen.height() and edit Show() method in class AdView

3 Likes

In addition to khoacng’s comment, you can also use the AdUtility.convert() too.
double height = AudienceNetwork.Utility.AdUtility.convert(Screen.height);
this.adView.Show(height - 50);

4 Likes

thank you my friend you saved my tons of hours

Same problem :frowning:

Could you possibly post your code snippet?

Got it. I kept forgetting the first line

this.adView.Register(this.gameObject);

        this.adView.AdViewDidLoad = (delegate() {
            Debug.Log("Banner loaded.");
            double height = AudienceNetwork.Utility.AdUtility.convert(Screen.height);
            this.adView.Show(height - 50);
        });
1 Like

This realy solve my problem thanks a lot guys .