【问题标题】:Google Admob banner ads not loading with AnchorType.topGoogle Admob 横幅广告未使用 AnchorType.top 加载
【发布时间】:2019-09-07 06:37:11
【问题描述】:

我有一个已在 Android 商店发布的 Flutter 应用程序。一切功能齐全,包括横幅广告。我现在正在尝试让应用程序的苹果端正常工作,并且一直在解决阻碍这个过程的无数苹果错误。

我目前无法解决的是横幅广告。他们只是根本没有出现在 iPhone 上。我已遵循此官方指南中的所有内容:https://developers.google.com/ad-manager/mobile-ads-sdk/ios/quick-start

我已将 Info.plist 中的 GADApplicationIdentifier 设置为 Admob 中我的应用的应用 ID。

我在 Info.plist 中添加了 GADIsAdManagerApp 并将其设置为 YES。

我在 Info.plist 中添加了 io.flutter.embedded_views_preview 并将其设置为 YES。

我已经从门户网站下载了一个最新的、新鲜的 GoogleService-info.plist 文件并将其添加到我的应用程序的 runner 文件夹中,但即使在完成所有这些步骤之后,我仍然得到:

并且没有其他信息可以提供有关失败原因的任何线索。

我的横幅代码(在 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");
    },
  );

有没有人在 IOS 中使用 Admob 横幅广告?


编辑:

所以我找到了错误的原因,但没有找到解决方案。整个问题都是由这一行引起的:

anchorType: AnchorType.top,

使用此设置,广告将完全无法在 IOS 上加载。如果我将其设置为底部,则广告加载非常好。似乎又是一个可怕的 IOS 错误,但我不知道如何解决这个问题,请记住我需要在屏幕顶部显示横幅。

有没有其他方法可以在不使用anchortype的情况下实现这种定位?

【问题讨论】:

  • 您的横幅添加 ID 是否正确?
  • 感谢朋友的回复。来自 Admob 的应用程序 ID 被复制并粘贴,并验证正确。它在 Android 中完美运行,所以它一定是。
  • 找到问题的原因,在上面的编辑中描述。
  • 仍然没有解决这个问题。无法理解为什么会这样。
  • @Bisclavret 我从未使用过横幅广告,但听起来你是对的,iOS 中有一个错误,广告显示在AppBar 上方,我添加了一个解决方案如何修复它。

标签: ios flutter banner-ads


【解决方案1】:

截图:

如果你使用AnchorType.top,试试这个:

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
);

如果你使用AnchorType.bottom,试试这个:

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,
);

经过测试(包括纵向和横向)

  • iPhone XS 模拟器
  • iPhone 6s 真机

【讨论】:

    猜你喜欢
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多