Reputation: 1351
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:
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?
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??
Upvotes: 2
Views: 1170
Reputation: 268214
Screenshot:
If you are using AnchorType.top
try this:
myBanner
..load()
..show(
anchorOffset: kToolbarHeight + 50, // 50 is the height of the banner ad
anchorType: AnchorType.top, // it should work now because we have added offset
);
If you are using AnchorType.bottom
try this:
myBanner
..load()
..show(
// it makes sure we are right below the AppBar, 50 is the height of Banner ad
anchorOffset: queryData.size.height - kToolbarHeight - 50 - queryData.padding.top - queryData.padding.bottom,
anchorType: AnchorType.bottom,
);
Tested on (including both portrait and landscape)
Upvotes: 1