예제 #1
0
        private void CreateNativeControl(UIViewController controller, MTAdView myMtAdView, string adsId, bool?personalizedAds, bool needToRefreshAdView)
        {
            if (!CrossMTAdmob.Current.IsEnabled)
            {
                return;
            }

            if (_adView != null && !needToRefreshAdView)
            {
                return;
            }

            _adUnitId = !string.IsNullOrEmpty(adsId) ? adsId : CrossMTAdmob.Current.AdsId;

            if (string.IsNullOrEmpty(_adUnitId))
            {
                Console.WriteLine("You must set the adsID before using it");
            }

            _adView = new BannerView(AdSizeCons.SmartBannerPortrait,
                                     new CGPoint(0, UIScreen.MainScreen.Bounds.Size.Height - AdSizeCons.Banner.Size.Height))
            {
                AdUnitId           = _adUnitId,
                RootViewController = controller
            };

            _adView.AdReceived += myMtAdView.AdImpression;


            var request = MTAdmobImplementation.GetRequest();

            //bool addExtra = false;
            //var dict = new Dictionary<string,string>();
            //if ((!personalizedAds.HasValue || !personalizedAds.Value) || !CrossMTAdmob.Current.UserPersonalizedAds)
            //{
            //    dict.Add(new NSString("npa"), new NSString("1"));
            //    addExtra = true;
            //}

            //if (CrossMTAdmob.Current.UseRestrictedDataProcessing)
            //{
            //    dict.Add(new NSString("rdp"), new NSString("1"));
            //    addExtra = true;
            //}

            //var request = GetRequest();
            //if (addExtra)
            //{
            //    var extras = new Extras
            //    {
            //        AdditionalParameters = NSDictionary.FromObjectsAndKeys(dict.Values.ToArray(), dict.Keys.ToArray())
            //    };
            //    request.RegisterAdNetworkExtras(extras);
            //}

            _adView.LoadRequest(request);
        }
예제 #2
0
        private void CreateNativeControl(MTAdView myMtAdView, string adsId, bool?personalizedAds)
        {
            if (!CrossMTAdmob.Current.IsEnabled)
            {
                return;
            }

            if (_adView != null)
            {
                return;
            }

            _adUnitId = !string.IsNullOrEmpty(adsId) ? adsId : CrossMTAdmob.Current.AdsId;

            if (string.IsNullOrEmpty(_adUnitId))
            {
                Console.WriteLine("You must set the adsID before using it");
            }

            var listener = new MyAdBannerListener();

            listener.AdClicked         += myMtAdView.AdClicked;
            listener.AdClosed          += myMtAdView.AdClosed;
            listener.AdImpression      += myMtAdView.AdImpression;
            listener.AdOpened          += myMtAdView.AdOpened;
            listener.AdFailedToLoad    += myMtAdView.AdFailedToLoad;
            listener.AdLoaded          += myMtAdView.AdLoaded;
            listener.AdLeftApplication += myMtAdView.AdLeftApplication;

            _adView = new AdView(Context)
            {
                AdSize           = _adSize,
                AdUnitId         = _adUnitId,
                AdListener       = listener,
                LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent)
            };

            var requestBuilder = MTAdmobImplementation.GetRequest();

            _adView.LoadAd(requestBuilder.Build());
        }