EtienneP EtienneP - 6 months ago 44
iOS Question

Xamarin.iOS Google Ads Targeting

I want to integrate Google Ads in my app, but I am stuck when it's time to load the request and get the Ad.

What I need is to pass targeting parameters to load an Ad related to my user's search.

I'm trying to load a

SearchRequest
for displaying a
SearchBannerView
, but no method seems to match my needs. The
LoadRequest
methods of the
SearchBannerView
do not accept
SearchRequest
. They only accept
Request
and no cast exists between those two classes.

However, the original Google docs says it's possible: https://developers.google.com/mobile-ads-sdk/docs/search-ads-for-apps/ios/

Here is my code:

this.banner = new SearchBannerView(AdSizeCons.Banner, new CGPoint(0, 0));
this.banner.TranslatesAutoresizingMaskIntoConstraints = false;
this.banner.AdSize = AdSizeCons.Banner;
this.banner.AdUnitID = this.AdService.AdMobUnitId;
this.banner.AdReceived += this.AdReceived;
this.banner.RootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

var request = new SearchRequest();
request.Query = ((GoogleAdViewModel)this.DataContext).Query;

// my request isn't accepted
this.banner.LoadRequest(request);


Has anyone succeed to make
SearchBannerView
load something using the Google Ads component from Xamarin?

It's for an iOS app and I'm using this component: https://components.xamarin.com/view/googleiosmobileads.

Answer

This question was answered here.

It was an issue in the binding library, the type SearchRequest had a wrong base type (NSObject instead of GADRequest).