locked
Unified native Advanced ads in xamarin.ios RRS feed

  • Question

  • User396424 posted

    Hi,

    I am trying to add Native Advanced (UnifiedNativeAds) in Xamarin.forms and was successful with Android but not with IOS the ads are blank. Below is my code -

    protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e);

            if (e.NewElement == null)
                return;
    
            if (e.OldElement == null)
            {
                AdSize adSize = new AdSize();
                adSize.Size = new CGSize(UIScreen.MainScreen.Bounds.Size.Width, 100);
    
                mAdView = new NativeExpressAdView(adSize)
                {
                    AdUnitId = "ca-app-pub-xxxxxxxxxxxxx/xxxxxxxxx",
                    RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
                };
    
                mAdView.AdReceived += (sender, args) =>
                {
                    if (!viewOnScreen) this.AddSubview(mAdView);
                    viewOnScreen = true;
                };
    
    
                Request request = Request.GetDefaultRequest();
    
    
                mAdView.LoadRequest(request);
    
               // adView.LoadRequest(Request.GetDefaultRequest());
                base.SetNativeControl(mAdView);
            }
    
        }
    

    Are there are any support links that i can refer to?

    For Android, I have created a layout in the Resources folder and I am binding the layout controls with ad controls. Can anyone tell me how to make something similar in IOS?

    I am new to xamarin development and having a hard time to figure out this. Even detail steps that can guide me to create advance native ads will be very helpful.

    Friday, October 16, 2020 5:14 PM

All replies

  • User369979 posted

    Have you read this blog: https://www.xamarinhelp.com/admob-xamarin-forms-display-google-ads-mobile-app/ You could also test the sample here: https://github.com/adamped/AdMob Have a try with:

    this.SetNativeControl(mAdView);
    
    Monday, October 19, 2020 7:32 AM
  • User396424 posted

    Hi LandLu,

    Thank you for the reply. Yes, I have read this blog. This for the Banner Ads which I have implemented successfully. My question is for UnifedNativeAds(NativeAdvanced Ads) which require us to create Native UIs in Android and IOS and Delegate to handle the AD response we get when the Ad is loaded.

    Please see this link - developers.google.com/ad-manager/mobile-ads-sdk/ios/native/advanced#layingoutthe_uiviews

    I followed this link article for Android Implementation - startdebugging.net/2019/09/admob-native-ads-in-xamarin-forms-android/ but couldn't figure out IOS implementation.

    Monday, October 19, 2020 1:22 PM
  • User369979 posted

    The code you posted looks like a banner ad. Refer to this doc: https://github.com/xamarin/GoogleApisForiOSComponents/blob/master/docs/Firebase/AdMob/GettingStarted.md#native-ads-advanced-unified for the initialization of Native Ads on iOS.

    Tuesday, October 20, 2020 9:08 AM