Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin form and Admob Component

$
0
0

Hi,

I wrote an iOS renderer to display an ad from Admob but the DidReceiveAd event never fires.
I'm using an iOS8 simulator and a version of the component dowloaded from someone on the forum which is supposed to be compatible with iOS8.
Here is my code.

            using System;
            using System.Collections.Generic;
            using System.Text;

            using Xamarin.Forms.Platform.iOS;
            using Xamarin.Forms;
            using FMN_Xamarin.Views;
            using FMN_Xamarin.iOS;
            using GoogleAdMobAds;

            [assembly: ExportRenderer(typeof(IntroView), typeof(AdmobRenderer))]
            namespace FMN_Xamarin.iOS
            {
                public class AdmobRenderer : PageRenderer
                {
                    const string AdmobID = "ca-app-pub-xxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxx ";
                    GADBannerView adView;
                    bool viewOnScreen = false;

                    bool hasShown;

                    public override void ViewDidLoad()
                    {
                        if (!hasShown)
                        {
                            hasShown = true;
                            base.ViewDidLoad();

                            adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new System.Drawing.PointF(0, 0))
                            {
                                AdUnitID = AdmobID,
                                RootViewController = this
                            };

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

                            GADRequest.Request.TestDevices = new string[1] { "GAD_SIMULATOR_ID" };
                            adView.LoadRequest(GADRequest.Request);
                        }
                    }

                }
            }

Tks.

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>