private void CreateNativeAdView() { if (!CrossAdMob.Current.IsEnabled) { return; } if (_adView != null) { return; } //adsId if (CrossAdMob.Current.IsInTestMode) { _adUnitId = GoogleSamplesAdUnitIds.AndroidSampleAdUnitId_Banner; } else { _adUnitId = !String.IsNullOrEmpty(_formsAdView.AdsId) ? _formsAdView.AdsId : !String.IsNullOrEmpty(CrossAdMob.Current.AdUnitId_Banner) ? CrossAdMob.Current.AdUnitId_Banner : GoogleSamplesAdUnitIds.AndroidSampleAdUnitId_Banner; } if (string.IsNullOrEmpty(_adUnitId)) { Console.WriteLine("You must set the adsID before using it"); } var listener = new AdMobListener(_formsAdView.AdsId); listener.AdClosed += _formsAdView.AdClosed; listener.AdOpened += _formsAdView.AdOpened; listener.AdFailedToLoad += _formsAdView.AdFailedToLoad; listener.AdLoaded += _formsAdView.AdLoaded; var adsize = getAdSize(); var back = new ColorDrawable(Color.Transparent.ToAndroid()); _adView = new AdView(Context) { Background = back, AdSize = adsize, AdUnitId = _adUnitId, AdListener = listener, LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) }; _adView.LoadAd(AdMobForms.GetRequest()); }
private void CreateNativeAdView(UIViewController controller) { if (!CrossAdMob.Current.IsEnabled) { return; } if (_adView != null) { return; } if (CrossAdMob.Current.IsInTestMode) { _adUnitId = GoogleSamplesAdUnitIds.iOSSampleAdUnitId_Banner; } else { _adUnitId = !String.IsNullOrEmpty(_formsAdView.AdsId) ? _formsAdView.AdsId : !String.IsNullOrEmpty(CrossAdMob.Current.AdUnitId_Banner) ? CrossAdMob.Current.AdUnitId_Banner : GoogleSamplesAdUnitIds.iOSSampleAdUnitId_Banner; } if (string.IsNullOrEmpty(_adUnitId)) { Console.WriteLine("You must set the adsID before using it"); } _adView = new BannerView(getAdSize(), new CGPoint(0, UIScreen.MainScreen.Bounds.Size.Height - AdSizeCons.Banner.Size.Height)) { AdUnitId = _adUnitId, RootViewController = controller, }; _adView.WillPresentScreen += _adView_WillPresentScreen; _adView.ReceiveAdFailed += _adView_ReceiveAdFailed; _adView.AdReceived += _adView_AdReceived; _adView.ScreenDismissed += _adView_ScreenDismissed; var request = AdMobForms.GetRequest(); _adView.LoadRequest(request); }