Xamarin Forms and Google Mobile Ads for iOS: update

In my previous post I explaind how to add on your application advertising. In those days Xamarin has removed from the Component Store the component called Google Mobile Ads for iOS.

Now you have to install another component called Firebase AdMob for iOS.

Firebase_admob_ios

After installed this component you can see in your Output window a similar info without see an advert in your app:

2016-11-18 11:28:14.853 WordBankEasy.iOS[11103:2250070] <Google> You must set the rootViewController property of <GADBannerView: 0x1034702c0; frame = (-10 0; 320 50); clipsToBounds = YES; layer = <CALayer: 0x174e39d40>> before loading a request.

To fix this issue you have to find before the right UIViewController. For that you can use the following code:

    UIViewController viewController = null;
    foreach (UIWindow rootView in UIApplication.SharedApplication.Windows) {
        if (rootView != null) {
            viewController = rootView.RootViewController;
        }
    }

    adView = new BannerView(size: AdSizeCons.Banner,
                            origin: new CGPoint(-10, 0))
    {
        AdUnitID = AdmobID,
        RootViewController = viewController
    };

Happy coding!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.