Capacitor Community Admob - 无广告显示 - 测试 IOS 广告不显示

问题描述 投票:0回答:1

我正在使用 Capacitor Community AdMob (v5.3.1) 在 Android 和 IOS 应用程序上显示横幅和插页式广告。我将 Angular 与 Ionic Framework 结合使用 - 除了“本机”内容(例如适用于 IOS 的 Info.plist)之外,代码库是相同的。

我在 AdMob 上将 iPhone 和 Android 手机设置为测试设备,这样我就可以展示真实的广告(但在测试模式下)。这些广告在 Android 手机上显示正常,但在 iPhone 上不起作用。我不断收到错误“没有可展示的广告”。尝试展示 iPhone 广告时。我仔细检查了我在 AdMob 中为 iPhone 设置的 IDFA 是否正确。我正在使用“我的设备标识符”应用程序获取 IDFA。该应用程序还为我提供了 IDFV,但我认为 IDFA 是正确使用的 ID。

我的 AdMob 帐户似乎没有任何限制。它为 Android 提供的广告效果很好,这一事实证明了这一点。

我能够在 iPhone 和 Android 上正常显示演示广告单元。我还发现,如果我在 AdMob.initialize 步骤中添加 iPhone 作为测试设备,则可以使用 Logcat 消息中显示的设备 ID(如下所示)显示测试广告:

2023-12-03 21:08:15.779400+0000 MyTestApp[1707:99269] <Google> To get test ads on this device, set: 
Objective-C
    GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"770185167e05233828007f06c16a1211" ];

这是我的初始化方法:

AdMob.initialize({
  testingDevices: environment.testingDevices,
  initializeForTesting: true,
});

我正在使用环境变量来存储测试设备 ID:

testingDevices: ['770185167e05233828007f06c16a1211','1E80E3909C199A8778EBFB88E5F9DA71']

如果我使用 AdMob.initialize 方法以编程方式添加测试设备,则 iPhone 测试广告显示正常。当然,在 Logcat 中使用 testDeviceIdentifier 的问题是,每次全新安装应用程序时,它都会发生变化,这就是为什么我只想将 iPhone 注册为 AdMob 上的测试设备,并拥有一个空的 AdMob.initialize。

我很困惑为什么它在 Android 设备上运行良好,但在 iPhone 上却不行。 iPhone 是否需要一些“额外”的东西才能用作测试设备,而不需要在 AdMob.initialize 中以编程方式注册?

我已经发现一些帖子建议我只需要等待几个小时即可显示 iPhone 广告,但这种情况已经持续了两周,所以我不认为这是一个计时/等待的问题。另外 - 如果按照前面提到的方式以编程方式添加 iPhone,广告就会正常工作,所以我不认为这是 AdMob 帐户的问题。

这是我的 Info.plist 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>MyTestApp</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(MARKETING_VERSION)</string>
    <key>CFBundleVersion</key>
    <string>$(CURRENT_PROJECT_VERSION)</string>
    <key>GADApplicationIdentifier</key>
    <string>ca-app-pub-7752708518900938~4403450338</string>
    <key>GADIsAdManagerApp</key>
    <true/>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSUserTrackingUsageDescription</key>
    <string>[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]</string>
    <key>SKAdNetworkItems</key>
    <array>
        <dict>
            <key>SKAdNetworkIdentifier</key>
            <string>cstr6suwn9.skadnetwork</string>
        </dict>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <true/>
</dict>
</plist>

这是我管理广告的广告组件:

import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { isPlatform } from "@ionic/angular";

//Capacitor AdMob plugin
import { AdMob, AdLoadInfo, BannerAdOptions, BannerAdSize, BannerAdPosition, BannerAdPluginEvents, AdMobBannerSize, AdOptions, InterstitialAdPluginEvents, AdMobError } from '@capacitor-community/admob';
import { environment } from 'src/environments/environment';

@Component({
  selector: 'app-advert',
  templateUrl: './advert.component.html',
  styleUrls: ['./advert.component.scss'],
})
export class AdvertComponent  implements OnInit {

  constructor(
    private platform: Platform) { 

    //init Ads
    this.initializeAds();
  }

  failedToLoadBannerAd: boolean = false;
  failedToLoadInterstitialAd: boolean = false;

  //delay for displaying ad banners
  bannerDelay : number = 5000;

  //delay for prepping ads (e.g. interstitial)
  prepAdsDelay : number = 5000;

  ngOnInit() {}

  async initializeAds() {
    const { status } = await AdMob.trackingAuthorizationStatus();
  
    if (status === 'notDetermined') {
      /**
       * 
       * If you want to explain TrackingAuthorization before showing the iOS dialog,
       * you can show the modal here.
       * ex)
       * const modal = await this.modalCtrl.create({
       *   component: RequestTrackingPage,
       * });
       * await modal.present();
       * await modal.onDidDismiss();  // Wait for close modal
       **/
    }
   
    AdMob.initialize({
      testingDevices: environment.testingDevices,
      initializeForTesting: true,
    });

    AdMob.addListener(BannerAdPluginEvents.FailedToLoad, (error: AdMobError) => {
      this.failedToLoadBannerAd = true;
    });

    AdMob.addListener(InterstitialAdPluginEvents.FailedToLoad, (error: AdMobError) => {
      this.failedToLoadInterstitialAd = true;
    });

    AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
      //console.log(`Ad loaded info: ${info}`);
    });

    //listener for interstit dismissed event
    AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
      this.prepInterstitialAd();
    });

    this.prepInterstitialAd();
    this.displayBannerAd();

  }

  //resets the 'failed to load ads' flags, so we can try to load again
  resetFailed(){

    this.failedToLoadBannerAd = false;
    this.failedToLoadInterstitialAd = false;

    //prep interstitial again
    this.prepInterstitialAd();

  }

  async showBanner()
  {
    const adId = isPlatform('ios') ? environment.iosBannerAdId : environment.androidBannerAdId;
    const options: BannerAdOptions = {
      adId: adId,
      adSize: BannerAdSize.ADAPTIVE_BANNER,
      position: BannerAdPosition.BOTTOM_CENTER,
      margin: 0,
      isTesting: false
      // npa: true
    };
    await AdMob.showBanner(options);
  }

  async hideBanner()
  {
    await AdMob.hideBanner();
  }

  async showInterstitial()
  {
    await AdMob.removeBanner();
    await AdMob.showInterstitial();
  }

  async prepInterstitialAd() {
    const adId = isPlatform('ios') ? environment.iosInterstitialVideoAdId : environment.androidInterstitialVideoAdId;
    const options: AdOptions = {
      adId: adId,
      
      isTesting: false
    }
    await AdMob.prepareInterstitial(options);
  }

  displayBannerAd(){
    setTimeout(() => {
      this.showBanner();
    }, this.bannerDelay);
  }

  prepAds() {
  setTimeout(() => {
    this.prepInterstitialAd();
  }, this.prepAdsDelay);
}

}
ios ionic-framework admob capacitor
1个回答
0
投票

我发现了问题所在。我的 IOS 手机被设置为 AdMob 上的测试设备。但我没有正确实现 IOS 的 ATT(应用程序透明度跟踪)。因此,当我请求广告时,Admob 没有获取手机的广告 ID/IDFA。所以它不知道这是一个测试设备。

一旦我正确实施 ATT,并在 ATT 弹出窗口中单击“允许”以允许跟踪手机的 IDFA,一切都会启动,测试广告现在可以正常显示。

如果您卸载并重新安装应用程序以重置 ATT,并在 ATT 对话框中单击“要求应用程序不跟踪”选项,Admob 将不会获取手机的 IDFA,并且不再显示广告。

这是预期的行为,一旦应用程序投入生产并启用生产广告,一切都应该正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.