/// <summary>
        /// reload the view and hit up google admob 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            //convert the element to the control we want
            var adMobElement = Element;

            // Setup your BannerView, review AdSizeCons class for more Ad sizes.
            adView = new BannerView(AdSizeCons.Banner)
            {
                AdUnitID = "ca-app-pub-5421996238963163/8238631737",
                RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
            };

            // Wire AdReceived event to know when the Ad is ready to be displayed
            adView.AdReceived += (sender, args) =>
            {
                if (!viewOnScreen)
                {
                    AddSubview(adView);
                }
                viewOnScreen = true;
            };

            adView.LoadRequest(Request.GetDefaultRequest());
            base.SetNativeControl(adView);
        }
Example #2
0
    public void RequestBanner()
    {
#if UNITY_ANDROID
        string adUnitId = "ca-app-pub-7216001829525156/4947676322";
        //string adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
        string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the top of the screen.
        this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        this.bannerView.LoadAd(request);
    }
    // Use this for initialization
    //   void Awake()
    //   {
    //       if (admobControll)
    //       {
    //           DestroyImmediate(this.gameObject);
    //           return;
    //       }
    //       admobControll = this;
    //       DontDestroyOnLoad(this.gameObject);
    //	RequestBanner();
    //}

    #region BannerAD
    private void RequestBanner()
    {
        if (bannerView != null)
        {
            bannerView.Destroy();
        }
        // Create a 320x50 banner at the top of the screen.
        bannerView = new BannerView(bannerID, AdSize.SmartBanner, AdPosition.Bottom);
        // Register for ad events.
        bannerView.AdLoaded          += HandleAdLoaded;
        bannerView.AdFailedToLoad    += HandleAdFailedToLoad;
        bannerView.AdOpened          += HandleAdOpened;
        bannerView.AdClosing         += HandleAdClosing;
        bannerView.AdClosed          += HandleAdClosed;
        bannerView.AdLeftApplication += HandleAdLeftApplication;
        // bannerView.LoadAd(createAdRequest());
        AdRequest request = new AdRequest.Builder().Build();

        bannerView.LoadAd(request);
    }
Example #4
0
    static public void RequestBanner()
    {
                #if UNITY_EDITOR
        string adUnitId = "unused";
                #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-xxxxxxxx";
                #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
                #else
        string adUnitId = "unexpected_platform";
                #endif

        // Create a 320x50 banner at the top of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the banner with the request and show it
        bannerView.LoadAd(request);
        bannerView.Show();
    }
Example #5
0
    private void RequestBanner()
    {
        #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-";
        #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-";
        #else
        string adUnitId = "unexpected_platform";
        #endif

        bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder()
                            //.AddTestDevice("")
                            .Build();

        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
Example #6
0
    private void RequestBannerAd()
    {
        //Create a BannerView
                #if UNITY_ANDROID
        string id = bannerIdAndroid;
                #elif UNITY_IOS
        string id = bannerIdIOs;
                #else
        Debug.Log("Unsupported platform");
        return;
                #endif

        bannerView = new BannerView(id, AdSize.Banner, AdPosition.Bottom);

        //Request an ad
        AdRequest req = new AdRequest.Builder().Build();

        //Load the banner with the request
        bannerView.LoadAd(req);
    }
    /*
     * Requests the banner depending on what platform you are on.
     * Currently I have no apple ID.
     */
    private void RequestBanner()
    {
        #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-8082064498416450/8145076128";
        #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
        #else
        string adUnitId = "unexpected_platform";
        #endif

        // Create a banner at the top of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);


        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
    private void RequestBanner()
    {
        #if UNITY_EDITOR
        string adUnitId = "ca-app-pub-3840620948536981/1651801756";
        #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-3840620948536981/1651801756";
        #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
        #else
        string adUnitId = "unexpected_platform";
        #endif

        // Create a 320x50 banner at the top of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
Example #9
0
    public void RequestBanner()
    {
        if (bannerView != null)
        {
            bannerView.Destroy();
        }
        AdSize adSize = bannerType == BannerType.Banner ? AdSize.Banner : AdSize.SmartBanner;

        // Create a 320x50 banner at the top of the screen.

        this.bannerView              = new BannerView(ID_BANNER, adSize, AdPosition.Bottom);
        bannerView.OnAdLoaded       += BannerLoadSucces;
        bannerView.OnAdFailedToLoad += BannerLoadFailed;
        // Load a banner ad.
        AdRequest request = new AdRequest.Builder()
                            .AddExtra("tag_for_under_age_of_consent", isUnder18Age ? "true" : "false")
                            .Build();

        this.bannerView.LoadAd(request);
    }
Example #10
0
    public void RequestBanner()
    {
        // Create a 320x50 banner at the top of the screen
        if (testMode)
        {
            this.bannerView = new BannerView(Android_Admob_Banner_ID, AdSize.Banner, AdPosition.Top);
        }
        else
        {
            // code for live ad
        }

        //Create an empty ad request
        AdRequest adRequest = new AdRequest.Builder().Build();

        // Load the banner with the request
        this.bannerView.LoadAd(adRequest);

        HideBanner();
    }
Example #11
0
    private void RequestBanner()
    {
        bannerView = new BannerView(bannerID, AdSize.Banner, AdPosition.Bottom);

        AdRequest request = null;

        if (!TestAds)
        {
            request = new AdRequest.Builder().Build();
        }

        if (TestAds)
        {
            request = new AdRequest.Builder()
                      .AddTestDevice(AdRequest.TestDeviceSimulator)     // Simulator.
                      .AddTestDevice(SystemInfo.deviceUniqueIdentifier) // My test device.
                      .Build();
        }
        bannerView.LoadAd(request);
    }
Example #12
0
    private void RequestBanner()
    {
        if (!Data.properties.ads.testMode)
        {
            #if UNITY_ANDROID
            string adUnitId = Data.properties.ads.androidUnitID;
            #elif UNITY_IPHONE
            string adUnitId = Data.properties.ads.iphoneUnitID;
            #else
            string adUnitId = "unexpected_platform";
            #endif

            // Create an empty ad request.
            request = new AdRequest.Builder().Build();

            // Create a 320x50 banner at the top of the screen.
            bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);

            // Load the banner with the request.
            bannerView.LoadAd(request);
        }
        else
        {
            #if UNITY_ANDROID
            string adUnitId = "ca-app-pub-3940256099942544/6300978111";
            #elif UNITY_IPHONE
            string adUnitId = "ca-app-pub-3940256099942544/2934735716";
            #else
            string adUnitId = "unexpected_platform";
            #endif

            // Create an empty ad request.
            request = new AdRequest.Builder().Build();

            // Create a 320x50 banner at the top of the screen.
            bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);

            // Load the banner with the request.
            bannerView.LoadAd(request);
        }
    }
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null)
            {
                return;
            }

            if (e.OldElement == null)
            {
                UIViewController viewCtrl = null;

                foreach (UIWindow v in UIApplication.SharedApplication.Windows)
                {
                    if (v.RootViewController != null)
                    {
                        viewCtrl = v.RootViewController;
                    }
                }

                adView = new BannerView(size: AdSizeCons.Banner, origin: new CGPoint(-10, 0))
                {
                    AdUnitID           = AdmobID,
                    RootViewController = viewCtrl
                };

                adView.AdReceived += (sender, args) =>
                {
                    if (!viewOnScreen)
                    {
                        this.AddSubview(adView);
                    }
                    viewOnScreen = true;
                };


                adView.LoadRequest(Request.GetDefaultRequest());
                base.SetNativeControl(adView);
            }
        }
Example #14
0
    private void RequestBanner()
    {
        isLoaded = false;

#if UNITY_EDITOR
        string adUnitId = "editor_platform";
#elif UNITY_ANDROID
        //REAL UNIT ID: ca-app-pub-5709626172947104/5053255593
        string adUnitId = "ca-app-pub-5709626172947104/5053255593";
#elif UNITY_IPHONE
        //REAL UNIT ID: ca-app-pub-5709626172947104/5516290029
        string adUnitId = "ca-app-pub-5709626172947104/5516290029";
#else
        string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the top of the screen.
        this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);


        // Called when an ad request has successfully loaded.
        this.bannerView.OnAdLoaded += this.HandleOnAdLoaded;
        // Called when an ad request failed to load.
        this.bannerView.OnAdFailedToLoad += this.HandleOnAdFailedToLoad;
        // Called when an ad is clicked.
        this.bannerView.OnAdOpening += this.HandleOnAdOpened;
        // Called when the user returned from the app after an ad click.
        this.bannerView.OnAdClosed += this.HandleOnAdClosed;
        // Called when the ad click caused the user to leave the application.
        this.bannerView.OnAdLeavingApplication += this.HandleOnAdLeavingApplication;


        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        //AdRequest request = new AdRequest.Builder().AddTestDevice("a452c97175ecae1bbdc010df18db29c8").Build();

        // Load the banner with the request.
        this.bannerView.LoadAd(request);

        isLoaded = true;
    }
Example #15
0
        public void RequestBannerAd(AdPosition adPostion)
        {
            if (adPostion == null)
            {
                return;
            }

                                #if UNITY_ANDROID
            string adUnitId = androidBannerAdUnitID;
                                #elif UNITY_IPHONE
            string adUnitId = IOSBannerAdUnitID;
                                #else
            string adUnitId = "unexpected_platform";
                                #endif

            adUnitId = adUnitId.Trim();

            if (string.IsNullOrEmpty(adUnitId))
            {
                return;
            }

            //Destroy current banner ad, if exists
            DestroyBannerAd();

            // Create a banner
            this.bannerView = new BannerView(adUnitId, AdSize.Banner, adPostion);

            // Register for ad events.
            this.bannerView.OnAdLoaded             += this.HandleBannerLoaded;
            this.bannerView.OnAdFailedToLoad       += this.HandleBannerFailedToLoad;
            this.bannerView.OnAdOpening            += this.HandleBannerOpened;
            this.bannerView.OnAdClosed             += this.HandleBannerClosed;
            this.bannerView.OnAdLeavingApplication += this.HandleBannerLeftApplication;

            // Create an empty ad request.
            AdRequest request = new AdRequest.Builder().Build();

            // Load the banner with the request.
            this.bannerView.LoadAd(request);
        }
Example #16
0
        private void inicializarComponente()
        {
            _bannerView = new BannerView {
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Fill,
                HeightRequest     = 160
            };

            _seguimentoGrid = new Grid {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Margin            = 5,
                RowSpacing        = 10,
                ColumnSpacing     = 10
            };

            /*
             * _seguimentoGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
             * _seguimentoGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
             * _seguimentoGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
             */
            _seguimentoGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            _seguimentoGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            _seguimentoGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            //_seguimentoGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });


            _empresaLabel = new Label {
                HorizontalOptions       = LayoutOptions.Fill,
                VerticalOptions         = LayoutOptions.Start,
                HorizontalTextAlignment = TextAlignment.Center,
                Margin = new Thickness(0, 5),
                Text   = "Smart Tecnologia ®"
            };
        }
        //------------------------------------------------------------
        // Banner Ads.
        //------------------------------------------------------------

        protected override void InternalShowBannerAd(AdPlacement placement, BannerAdPosition position, BannerAdSize size)
        {
            #if EM_ADMOB
            string id = placement == AdPlacement.Default ?
                        mAdSettings.DefaultBannerAdId.Id :
                        FindIdForPlacement(mAdSettings.CustomBannerAdIds, placement);

            if (string.IsNullOrEmpty(id))
            {
                Debug.Log("Attempting to show AdMob banner ad with an undefined ID at placement " + AdPlacement.GetPrintableName(placement));
                return;
            }

            // If the requested banner (default or custom) doesn't exist or player request a banner with different size, create a new one and show it.
            // Otherwise just show the existing banner (which might be hidden before).

            if (placement == AdPlacement.Default) // Default banner...
            {
                if (mDefaultBanner == null || mCurrentDefaultBannerSize != size)
                {
                    mDefaultBanner            = CreateNewBanner(position, size, id);
                    mCurrentDefaultBannerSize = size;
                    Debug.Log("Creating new default banner...");
                }

                mDefaultBanner.SetPosition(ToAdMobAdPosition(position));
                mDefaultBanner.Show();
            }
            else // Custom banner...
            {
                if (!mCustomBannerAds.ContainsKey(placement) || mCustomBannerAds[placement].Value == null || mCustomBannerAds[placement].Key != size)
                {
                    mCustomBannerAds[placement] = new KeyValuePair <BannerAdSize, BannerView>(size, CreateNewBanner(position, size, id));
                    Debug.Log("Creating new custom banner...");
                }

                mCustomBannerAds[placement].Value.SetPosition(ToAdMobAdPosition(position));
                mCustomBannerAds[placement].Value.Show();
            }
            #endif
        }
    private void RequestBanner()
    {
        #if UNITY_EDITOR
        string adUnitId       = "unused";
        string adUnitIdBottom = "unused";
        #elif UNITY_ANDROID
        string adUnitId       = "ca-app-pub-2335297199953104/6284037477";
        string adUnitIdBottom = "ca-app-pub-2335297199953104/8317343874";
        #elif UNITY_IPHONE
        string adUnitId = "";
        #else
        //windows?
        string adUnitId = "";
        #endif

        // Create a 320x50 banner at the top of the screen.
        bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
        // Register for ad events.
        bannerView.AdLoaded          += HandleAdLoaded;
        bannerView.AdFailedToLoad    += HandleAdFailedToLoad;
        bannerView.AdOpened          += HandleAdOpened;
        bannerView.AdClosing         += HandleAdClosing;
        bannerView.AdClosed          += HandleAdClosed;
        bannerView.AdLeftApplication += HandleAdLeftApplication;
        // Load a banner ad.
        bannerView.LoadAd(createAdRequest());



        // Create a 320x50 banner at the bottom of the screen.
        bannerViewBottom = new BannerView(adUnitIdBottom, AdSize.SmartBanner, AdPosition.Bottom);
        // Register for ad events.
        bannerViewBottom.AdLoaded          += HandleAdLoaded;
        bannerViewBottom.AdFailedToLoad    += HandleAdFailedToLoad;
        bannerViewBottom.AdOpened          += HandleAdOpened;
        bannerViewBottom.AdClosing         += HandleAdClosing;
        bannerViewBottom.AdClosed          += HandleAdClosed;
        bannerViewBottom.AdLeftApplication += HandleAdLeftApplication;
        // Load a banner ad.
        bannerViewBottom.LoadAd(createAdRequest());
    }
Example #19
0
    public void RequestBanner()
    {
        // Clean up banner ad before creating a new one.
        if (this.bannerView != null)
        {
            this.bannerView.Destroy();
        }

        // Create a 320x50 banner at the top of the screen.
        this.bannerView = new BannerView(BannerID, AdSize.SmartBanner, AdPosition.Bottom);

        // Register for ad events.
        this.bannerView.OnAdLoaded             += this.HandleAdLoaded;
        this.bannerView.OnAdFailedToLoad       += this.HandleAdFailedToLoad;
        this.bannerView.OnAdOpening            += this.HandleAdOpened;
        this.bannerView.OnAdClosed             += this.HandleAdClosed;
        this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;

        // Load a banner ad.
        this.bannerView.LoadAd(this.CreateAdRequest());
    }
Example #20
0
        public void Request()
        {
            if (isLoading)
            {
                Debug.LogError("Banner Ad is loading, Please try again later.");
            }
            else if (isPlaying)
            {
                Debug.LogError("Banner Ad is playing, Please hide then try again.");
            }
            else
            {
                if (bannerView != null)
                {
                    bannerView.Destroy();
                    bannerView = null;
                }

                RequestBanner();
            }
        }
Example #21
0
    private void requestBanner()
    {
#if GLOWBOM_ADS
#if UNITY_ANDROID
        string adUnitId = androidBanner;
#elif UNITY_IPHONE
        string adUnitId = iOSBanner;
#else
        string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the top of the screen.
        this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.BottomRight);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        this.bannerView.LoadAd(request);
#endif
    }
Example #22
0
    private void RequestBanner()
    {
#if UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
        string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the top of the screen.
        _bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);

        _bannerView.OnAdLoaded += HandleOnAdLoaded;

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        _bannerView.LoadAd(request);
    }
Example #23
0
    private void RequestBanner()

    {
#if UNITY_ANDROID
        string AdUnitID = "";
#else
        string AdUnitID = "unDefind";
#endif

        banner = new BannerView(AdUnitID, AdSize.Banner, AdPosition.Bottom);



        //AdRequest request = new AdRequest.Builder().Build();
        AdRequest request =
            new AdRequest.Builder().AddTestDevice(AdRequest.TestDeviceSimulator).AddTestDevice("C251A04598CF28276A850C491D2B598B").Build();

        banner.LoadAd(request);
        banner.Show();
        isAdsBannerSet = true;
    }
Example #24
0
    /// <summary>
    /// Loads the bottom banner if it is not already loaded or loading
    /// </summary>
    private void LoadBottomBanner()
    {
        if (bottomBannerState == BannerState.Idle)
        {
            if (bottomBanner == null)
            {
                // Create the banner view
                bottomBanner = new BannerView(BannderAdUnitId, AdSize.SmartBanner, AdPosition.Bottom);

                // Set the event callbacks for the bottom banner
                bottomBanner.OnAdLoaded       += OnBottomBannerLoaded;
                bottomBanner.OnAdFailedToLoad += OnBottomBannerFailedToLoad;
            }

            // Set the state to loading
            bottomBannerState = BannerState.Loading;

            // Load and show the banner
            bottomBanner.LoadAd(CreateAdRequest());
        }
    }
Example #25
0
    private void RequestBanner()
    {
                #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-9335373935858246/3343573160";
                #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/2934735716";
                #else
        string adUnitId = "unexpected_platform";
                #endif

        // Create a 320x50 banner at the top of the screen.
        AdSize adSize = new AdSize(250, 250);
        bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
        AdRequest requestBanner = new AdRequest.Builder()
                                  .AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator.
                                  .Build();


        bannerView.LoadAd(requestBanner);
        bannerView.Show();
    }
Example #26
0
    public void RequestBanner()
    {
        #if UNITY_ANDROID
        // string adUnitId = "ca-app-pub-3940256099942544/6300978111"; // TEST
        string adUnitId = "ca-app-pub-2228911308495304/2188490667";                 // LIVE
        #elif UNITY_IPHONE
        // string adUnitId = "ca-app-pub-3940256099942544/2934735716"; // TEST
        string adUnitId = "ca-app-pub-2228911308495304/5922859143";                 // LIVE
        #else
        string adUnitId = "unexpected_platform";
        #endif

        // Create a 320x50 banner at the bottom of the screen.
        bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
Example #27
0
    private void RequestBanner()
    {
        string adUnitId = "ca-app-pub-1987428931362758/2456676520";

        // Create a 320x50 banner at the top of the screen.
        bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

        // Called when an ad request has successfully loaded.
        bannerView.OnAdLoaded += HandleOnAdLoaded;
        // Called when an ad request failed to load.
        bannerView.OnAdFailedToLoad += HandleOnAdFailedToLoad;
        // Called when an ad is clicked.
        bannerView.OnAdOpening += HandleOnAdOpened;
        // Called when the user returned from the app after an ad click.
        bannerView.OnAdClosed += HandleOnAdClosed;
        // Called when the ad click caused the user to leave the application.
        bannerView.OnAdLeavingApplication += HandleOnAdLeavingApplication;

        // Create an empty ad request.
        request = new AdRequest.Builder().Build();
    }
Example #28
0
    private void RequestBanner()
    {
                #if UNITY_EDITOR
        string adUnitId = "ca-app-pub-3940256099942544/6300978111";                 // test ad banner id
                #elif UNITY_ANDROID
        string adUnitId = BannerId;
                #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
                #else
        string adUnitId = "unexpected_platform";
                #endif

        // Create a 320x50 banner at the bottom of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
Example #29
0
    private void RequestBanner()
    {
        #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-6239259349327423/2946607284";
        #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/2934735716";
        #else
        string adUnitId = "unexpected_platform";
        #endif

        // Create a 320x50 banner at the top of the screen.
        this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // AdSize adSize = new AdSize(250, 250);
        // BannerView bannerView = new BannerView(adUnitId, adSize, AdPosition.Bottom);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        this.bannerView.LoadAd(request);
    }
    private void RequestBanner()
    {
        string adUnitId = "ca-app-pub-3753271744047506/8215960620";

        // Create a 320x50 banner at the top of the screen.
        bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the banner with the request.
        bannerView.LoadAd(request);

        // Called when an ad request has successfully loaded.
        bannerView.OnAdLoaded += HandleOnAdLoaded;
        // Called when an ad request failed to load.
        bannerView.OnAdFailedToLoad += HandleOnAdFailedToLoad;
        // Called when an ad is clicked.
        bannerView.OnAdOpening += HandleOnAdOpened;
        // Called when the user returned from the app after an ad click.
        bannerView.OnAdClosed += HandleOnAdClosed;
    }
    // spruce id ca-app-pub-9437415255143113/2042268588

    private void showBannerAd()
    {
        string adID = "ca-app-pub-9437415255143113/8076428235";



        //test id ca-app-pub-3940256099942544/2934735716

        //**For Testing in the Device**

        /*AdRequest request = new AdRequest.Builder()
         *      .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
         *      .AddTestDevice("33BE2250B43518CCDA7DE426D04EE232")  // My test device.
         *      .Build();*/

        //**For Production When Submit App**
        AdRequest request = new AdRequest.Builder().Build();

        bannerAd = new BannerView(adID, AdSize.SmartBanner, AdPosition.Bottom);
        bannerAd.LoadAd(request);
    }
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);
            if (Control == null)
            {
                var adsbanner = (AdBanner)Element;
                adView = new BannerView(size: AdSizeCons.Banner, origin: new CGPoint(0, 0))
                {
                    AdUnitID = adsbanner.AdID,
                    RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
                };

                adView.AdReceived += (sender, args) => {
                    if (!viewOnScreen)
                        this.AddSubview(adView);
                    viewOnScreen = true;
                };

                adView.LoadRequest(Request.GetDefaultRequest());
                base.SetNativeControl(adView);
            }

        }