Wednesday 11 September 2019

Google Admob ads not loading in IOS, Flutter

I have a Flutter application that I have released on the Android store. Everything is fully functional, including the banner ads. I am trying now to get the apple side of the application working, and have been ironing through the myriad apple bugs that stand in the way of this process.

What I am unable to resolve at this point is the banner ads. They just do not show up at all on the iphone. I have followed everything in this official guide: https://developers.google.com/ad-manager/mobile-ads-sdk/ios/quick-start

I have set the GADApplicationIdentifier in Info.plist to the app ID of my app from Admob.

I have added GADIsAdManagerApp in Info.plist and set it to YES.

I have added io.flutter.embedded_views_preview in Info.plist and set it to YES.

I have downloaded an up to date, fresh GoogleService-info.plist file from the portal and added it to the runner folder of my app, but even after all these steps I get:

apple error

And no other information that may give any clues as to the reason for the failure.

My code for the banners (working fine in Android):

  @override
  void initState() {
    FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-XXXXXXXXXX~XXXXXX');
    _loadBannerState();
    super.initState();
  }

  _loadBannerState() async {
      myBanner
        ..load()
        ..show(
          anchorOffset: 0.0,
          anchorType: AnchorType.top,
        );
    }
  }

  static MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    keywords: <String>['flutterio', 'beautiful apps'],
    contentUrl: 'https://flutter.io',
    childDirected: false,
    designedForFamilies: true,
    gender: MobileAdGender.unknown,
    testDevices: <String>["XXXXXXXXXXXXXXXXXX"], // Android phone
  );

  BannerAd myBanner = BannerAd(
    adUnitId: 'ca-app-pub-XXXXXXXXX/XXXXXXXXXX', //Banner_OnePlayer
    size: AdSize.banner,
    targetingInfo: targetingInfo,
    listener: (MobileAdEvent event) {
      print("BannerAd event is $event");
    },
  );

Has anyone got Admob banner ads working in IOS?

EDIT:

So I have found the cause of the error but not the solution. The entire problem is caused by this one line:

anchorType: AnchorType.top,

With this set, the ad will completely fail to load on IOS. If I set this to bottom, the ad loads perfectly fine. Seems like yet another terrible IOS bug but I have no idea how to resolve this, bearing in mind that I need the banner to be displayed at the top of the screen.

Is there another way to achieve this positioning without using anchortype??



from Google Admob ads not loading in IOS, Flutter

No comments:

Post a Comment