Ionic 电容社区Admob -没有广告显示-测试IOS广告不显示

e5nszbig  于 12个月前  发布在  Ionic
关注(0)|答案(1)|浏览(144)

我使用电容器社区AdMob(v5.3.1)在Android和iOS应用程序上显示横幅和插播广告。我使用Angular与Ionic框架-代码库是相同的,除了“原生”的东西,如IOS的Info.plist。
我将iPhone和Android手机都设置为AdMob上的测试设备,这样我就可以显示真实的广告(但处于测试模式)。广告在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" ];

字符串
这是我的initialize方法:

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


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

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


如果我使用AdMob.initialize方法以编程方式添加测试设备,iPhone测试广告显示OK。当然,在Logcat中使用testDeviceIdentifier的问题是,它会随着应用程序的每次新安装而改变,这就是为什么我想简单地将iPhone注册为AdMob上的测试设备,并拥有一个空的AdMob. initialize。
我很难理解为什么它在Android设备上工作得很好,但在iPhone上却不行。iPhone作为一个测试设备工作,不需要在AdMob.initialize中以编程方式注册,是否需要一些“额外”的东西?
我已经发现了一些帖子,建议我只需要等待几个小时的iPhone广告显示,但这已经持续了2周,所以我不认为这是一个时间/等待的事情。此外-广告工作正常,如果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);
}

}

zbwhf8kr

zbwhf8kr1#

我发现了问题所在。我的IOS手机在AdMob上被设置为测试设备。但是我没有正确地实现ATT(应用透明度跟踪)。所以当我请求广告时,AdMob没有获得手机的广告ID/IDFA。所以它不知道这是一个测试设备,因此,没有广告显示。
一旦我正确地实现了ATT,并点击了ATT弹出窗口上的“允许”,允许跟踪手机的IDFA,一切都启动了,测试广告现在显示正常。
如果您卸载并重新安装应用程序以重置ATT,并在ATT对话框中单击“要求应用程序不跟踪”选项,Admob不会获得手机的IDFA,并且它不再显示广告。
这是预期的行为,一旦应用程序进入生产,并启用生产广告,一切都应该正常工作。

相关问题