Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase_admob plugin displays smart banner at top instead of bottom #27457

Closed
westy92 opened this issue Feb 3, 2019 · 21 comments
Closed

firebase_admob plugin displays smart banner at top instead of bottom #27457

westy92 opened this issue Feb 3, 2019 · 21 comments
Labels
p: firebase_admob Plugin to show Firebase AdMob ads p: firebase Firebase plugins package flutter/packages repository. See also p: labels.

Comments

@westy92
Copy link
Contributor

westy92 commented Feb 3, 2019

firebase_admob's show() method by default sets the anchorType to AnchorType.bottom. However, this setting isn't being honored on iOS 8, 9, and 10. iOS 11 and 12 appear to work fine.

About 10% of the time, it works as expected. 🤔

Steps to Reproduce

  1. Run the below sample code on iOS 8-10.
  2. The banner should be at the bottom.
  3. Instead, the banner is at the top.
import 'package:firebase_admob/firebase_admob.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MainPage(),
    );
  }
}

class MainPage extends StatefulWidget {
  @override
  MainPageState createState() => MainPageState();
}

class MainPageState extends State<MainPage> {
  BannerAd _bannerAd;

  @override
  void initState() {
    super.initState();
    FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
  }

  @override
  Widget build(BuildContext context) {
    _bannerAd ??= createBannerAd();
    _bannerAd..load()..show();
    return Container();
  }

  BannerAd createBannerAd() {
    return BannerAd(
      adUnitId: BannerAd.testAdUnitId,
      size: AdSize.smartBanner,
      listener: (MobileAdEvent event) {
        print('BannerAd event $event');
      },
    );
  }
}

Logs

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, locale en-US)
    • Flutter version 1.0.0 at /Users/westy92/Source/flutter
    • Framework revision 5391447fae (8 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
 
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/westy92/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.
 
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.6.0.beta.2
 
[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.3
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
 
[✓] VS Code (version 1.30.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1
 
[✓] Connected device (1 available)
    • Seth's iPod touch • <redacted> • ios • iOS 9.3.5
 
• No issues found!

Below are simulators, in order: iOS 8.4, 9.3, 10.3.1, 11.4, 12.1.

image

@kangwang1988 kangwang1988 added p: first party p: firebase_admob Plugin to show Firebase AdMob ads labels Feb 3, 2019
@zoechi zoechi added plugin p: firebase Firebase plugins labels Feb 7, 2019
@zoechi zoechi added this to the Goals milestone Feb 7, 2019
@fhuonder
Copy link
Contributor

fhuonder commented Feb 8, 2019

We see this behavior as well.
Would be great when it could be fixed soon.

Regards,
Florian

@zoechi
Copy link
Contributor

zoechi commented Feb 11, 2019

@sdolsky Using "add reaction" on the initial comment would increase priority.

@Toubap
Copy link

Toubap commented Mar 8, 2019

Also encountering this issue with last dev versions

@gzimbron
Copy link

gzimbron commented Apr 5, 2019

i have this problem too!

@Phorez
Copy link

Phorez commented May 1, 2019

Same here!

@itielMaimon
Copy link

Any news?

@skyberk
Copy link

skyberk commented May 23, 2019

Finally I found the solution. The main reason of the problem translatesAutoresizingMaskIntoConstraints property is setting to NO on pre ios 11. And location calculations will not be apply in this layout.

Move the following code line _banner.translatesAutoresizingMaskIntoConstraints = NO; to inside of the if (@available(ios 11.0, *)) statement in FLTMobileAd.m file.

_banner.translatesAutoresizingMaskIntoConstraints = NO;
UIView *screen = [FLTMobileAd rootViewController].view;
[screen addSubview:_banner];

#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)
if (@available(ios 11.0, *)) {
UILayoutGuide *guide = screen.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[
[_banner.centerXAnchor constraintEqualToAnchor:guide.centerXAnchor],
[_banner.bottomAnchor
constraintEqualToAnchor:_anchorType == 0 ? guide.bottomAnchor : guide.topAnchor
constant:_anchorOffset]
]];
} else {
[self placeBannerPreIos11];
}

To

UIView *screen = [FLTMobileAd rootViewController].view;
[screen addSubview:_banner];

#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)
if (@available(ios 11.0, *)) {
_banner.translatesAutoresizingMaskIntoConstraints = NO;
UILayoutGuide *guide = screen.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[
[_banner.centerXAnchor constraintEqualToAnchor:guide.centerXAnchor],
[_banner.bottomAnchor
constraintEqualToAnchor:_anchorType == 0 ? guide.bottomAnchor : guide.topAnchor
constant:_anchorOffset]
]];
} else {
[self placeBannerPreIos11];
}

For more information about this property you can visit the link below.
https://developer.apple.com/documentation/uikit/uiview/1622572-translatesautoresizingmaskintoco

And the result
Screen Shot 2019-05-24 at 00 21 27

@westy92
Copy link
Contributor Author

westy92 commented May 24, 2019

Great find! 🎉

@westy92
Copy link
Contributor Author

westy92 commented Jul 12, 2019

The open PR looks promising! Hoping it gets some attention. 🤞

@douglascaurismo
Copy link

I had the same problem (on ios 10), the banner that should be placed at the centered at the bottom is appearing in top left corner. After a while when the ad changes to the next, it gets its position fixed.

I was wondering why this project does not offer a way to place ads inside the widget tree.
That would be a huge improvement.

@kroikie
Copy link

kroikie commented Oct 13, 2019

@westy92

This issue has been moved to firebase/flutterfire#467. Any further collaboration will be done there.

@kroikie
Copy link

kroikie commented Oct 14, 2019

Since firebase_admob issues require work on the Flutter side as well as the plugin side these issues will remain open here as well until resolved.

@kroikie kroikie reopened this Oct 14, 2019
@iapicca
Copy link
Contributor

iapicca commented Oct 24, 2019

Hi @westy92
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca iapicca closed this as completed Oct 24, 2019
@izinin
Copy link

izinin commented Dec 25, 2019

@westy92

This issue has been moved to FirebaseExtended/flutterfire#467. Any further collaboration will be done there.

please do not make cyclic reference because [firebase/flutterfire#467] refers to this bug report https://github.com/FirebaseExtended/flutterfire/issues/467#issuecomment-541444232 . noise .. :(

@inuyashaaa
Copy link

i have this problem too!

@izinin
Copy link

izinin commented Feb 20, 2020

@inuyashaaa : i integrated fix, suggested somewhere here in forked repo https://github.com/izinin/flutterfire.git ,try this in pubspec.yaml (below) I hope in new version admob_firebase the issue will be fixed officially:

diff:

      -  firebase_admob: ^0.9.0+10
      +  
      +  # workaround for
      +  # https://github.com/FirebaseExtended/flutterfire/pull/45/files
      +  # adjusting adBanner https://github.com/flutter/flutter/issues/14222
      +  firebase_admob: #^0.9.0+10
      +    git: 
      +      url: https://github.com/izinin/flutterfire.git
      +      path: packages/firebase_admob
      +      ref: admob_fix_missplaced_banner
      +

@iapicca
Copy link
Contributor

iapicca commented Feb 20, 2020

Could everyone who still has this problem please file a new issue
in the dedicated github
with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please.
All system setups can be slightly different so it's always better to open new issues and reference related issues.

@dayron9110
Copy link

Any updates?

@iapicca
Copy link
Contributor

iapicca commented Dec 11, 2020

@dayron9110
this issue is a duplicate, please follow up here

@dayron9110
Copy link

How Can I fix this issue? @iapicca

@github-actions
Copy link

github-actions bot commented Aug 8, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: firebase_admob Plugin to show Firebase AdMob ads p: firebase Firebase plugins package flutter/packages repository. See also p: labels.
Projects
None yet