ios - 未使用AnchorType.top加载的Google Admob标语广告

标签 ios flutter banner-ads

我有一个在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文件,并将其添加到应用程序的运行程序文件夹中,但是即使经过所有这些步骤,我仍然可以:

apple error

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

我的横幅广告代码(在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即可实现此定位的方法吗?

最佳答案

屏幕截图:

enter image description here

如果您使用的是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真实设备
  • 关于ios - 未使用AnchorType.top加载的Google Admob标语广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57831318/

    相关文章:

    flutter - 如何在flutter中动态向pdf添加内部导航

    flutter - 如何从它自己的 onTap 中禁用 ListTile?

    android - 如何在请求广告时使 AdView "occupy"空间? (安卓)

    iphone - iad的banner不需要设置吗?

    Flutter AdMob Banner 广告重叠屏幕

    ios - UINavigationView 弹出到 Root View Controller 问题

    ios - 使用swift在后台播放歌曲的本地通知?

    ios - 使用延迟参数在 objective-c 中创建方法

    ios - 在 iOS 中为任意层属性设置动画

    flutter - 在 Flutter 上检测推送的路由