【问题标题】:Handling iAd fail to receive Ad within Admob Mediation setup处理 iAd 无法在 Admob 中介设置中接收广告
【发布时间】:2012-12-27 05:55:01
【问题描述】:

我使用 AdMob 中介服务设置了一个基本应用程序作为测试。

- (void)viewDidLoad {
      [super viewDidLoad];

      // Create a view of the standard size at the top of the screen.
      // Available AdSize constants are explained in GADAdSize.h.
      bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

      // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
      bannerView_.adUnitID = kAdMobPublisherID;

      // Let the runtime know which UIViewController to restore after taking
      // the user wherever the ad goes and add it to the view hierarchy.
      bannerView_.rootViewController = self;
      [self.view addSubview:bannerView_];

      // Initiate a generic request to load it with an ad.
      [bannerView_ loadRequest:[GADRequest request]];

      GADRequest *request = [GADRequest request];
      // Make the request for a test ad. Put in an identifier for
      // the simulator as well as any devices you want to receive test ads.
      request.testDevices = [NSArray arrayWithObjects:
                             @"4D047EB9-A3A7-441E-989E-C5437F05DB04",
                             @"YOUR_DEVICE_IDENTIFIER",
                             nil];

 }

当应用程序无法接收广告时,我会收到这些错误消息。我相信 iAd 在测试 iAd 广告期间会发送相当多的错误。

[AppDeveloper]: ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=4 "The operation couldn’t be completed. Application has iAd Network configuration error" UserInfo=0x9fd8d20 {ADInternalErrorCode=4, ADInternalErrorDomain=ADErrorDomain, NSLocalizedFailureReason=Application has iAd Network configuration error}

该错误是由于未实现 didFailToReceiveAdWithError 所致。我的问题是如何实现这个方法。

我查看了 iAd 节目指南:iAd Prog Guide

这建议设置这样的方法...

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error

但是,由于我的代码没有直接实现 iAd 网络,它是使用中介服务设置的。我不确定如何更改上述方法。

【问题讨论】:

    标签: ios ios5 ios-simulator admob iad


    【解决方案1】:

    我认为你错过了添加行:

    bannerView_.delegate = self;
    

    【讨论】:

    • 我没有在你的代码中看到任何错误,只需检查bannerView_是GADBannerView类型。
    【解决方案2】:

    因为 AdMob 框架会处理广告展示(即使中介到 iAd 等其他广告来源),您只需要实现对 AdMob 横幅的处理。如果 AdMob 框架通过中介显示 iAd,它会将其封装并像任何常规 AdMob 横幅一样呈现给您。 因此,您只需设置bannerView 的委托以接收来自 AdMob 框架的事件,例如让您的视图控制器实现GADBannerViewDelegate 协议并将其用作委托):

    @interface MyViewController : UIViewController <GADBannerViewDelegate>
    ...
    

    在您的 viewDidLoad 方法中:

    bannerView_.delegate = self;
    

    然后您可以添加各种方法来处理广告事件,例如

    - (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error;
    

    在无法请求广告时调用。也很有用:

    - (void)adViewDidReceiveAd:(GADBannerView *)bannerView;
    

    每当成功接收到广告时都会调用它。此方法通常用于在广告横幅中滑动。传递的bannerView 始终属于GADBannerView 类,但它有一个属性mediatedAdView,其中包含要显示的实际广告(可能是iAd 横幅)。

    顺便说一句,您正在代码中准备广告请求,但实际上并未使用它来加载广告。您可能还想向下移动 loadRequest: 调用并使用准备好的请求:

    [bannerView_ loadRequest:request];
    

    有关 AdMob SDK 文档中的 GADBannerViewDelegate 方法的更多信息,请访问:https://developers.google.com/mobile-ads-sdk/docs/admob/intermediate

    【讨论】:

    • 谢谢,您能否进一步解释您的最后一点。 loadRequest:request 行是否应该位于上述 (qu) 代码的底部?
    • 是的,loadRequest 实际上启动了获取广告的请求。您问题中的代码使用新创建的请求对象调用 loadRequest ,然后创建另一个请求对象,对其进行配置(设置测试设备)并丢弃它。未配置实际运行请求(我想这是您想要做的)。正确的顺序是:GADRequest *request = [GADRequest request]; request.property = 值; [bannerView_loadRequest:request];
    猜你喜欢
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多