adWhirl的actualadsize方法没有返回正确的信息

发布于 2025-01-01 02:50:03 字数 341 浏览 1 评论 0原文

我正在对此进行测试:

  CGSize adSize = [adWhirlView actualAdSize];
NSLog(@"ad size received: %f x %f",adSize.width, adSize.height);

但是,返回的宽度始终是设备方向的宽度,无论广告实际上是什么样子。这主要是 adMob 的问题,因为它的广告可能远小于设备的宽度,因此显示为左齐平而不是居中,即使上面返回的 adsize 实际上显示的广告应该是全宽。

还有其他人遇到过这种情况并对如何处理有建议吗?如果您不知道广告的实际宽度,则无法真正将其正确居中。

I am testing with this:

  CGSize adSize = [adWhirlView actualAdSize];
NSLog(@"ad size received: %f x %f",adSize.width, adSize.height);

However, the width that is returned is always the width of the device orientation, no matter what the ad actually looks like. This is primarily an issue with adMob because its ads may be much less than the device's width and thus appear as flush left instead of centered, even though the adsize returned above is actually showing the ads are supposed to be full width.

Anyone else encountered this and have a suggestion on how to deal with it? If you don't know an ad's actual width, you cannot really center it properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撑一把青伞 2025-01-08 02:50:03

问题出在 AdMob 适配器中:

  // Set the frame for this view to match the bounds of the parent adWhirlView.
  GADBannerView *view =
  [[GADBannerView alloc] initWithFrame:adWhirlView.bounds];

这是一个非常糟糕的实现,因为 AdWhirl 缺少可选的委托方法。虽然这很容易解决。只需使用 AdMobs 横幅尺寸之一即可,一切都会正常:

  GADBannerView *view =
  //[[GADBannerView alloc] initWithFrame:adWhirlView.bounds];
[[GADBannerView alloc] initWithFrame:CGRectMake(0, 0, GAD_SIZE_468x60.width, GAD_SIZE_468x60.height)];

您可能还想修复颜色。有两个与颜色有关的错误:

  • AdMob 适配器确实使用了正确的委托方法(adWhirlAdBackgroundColor、adWhirlTextColor)。尽管如此,他只是使用文本的背景颜色。
  • 如果未实现颜色委托方法,AdMob 适配器不会回退到您在配置中定义的颜色。

要解决此问题,只需找到与颜色相关的代码(位于 getAd() 的开头)并将其替换为:

  if ((value = [self delegateValueForSelector:
                      @selector(adWhirlAdBackgroundColor)])) {
    [additional setObject:[self hexStringFromUIColor:(UIColor *)value]
                  forKey:@"color_bg"];
  } else {
    [additional setObject:[self hexStringFromUIColor:adWhirlConfig.backgroundColor]
                     forKey:@"color_bg"];
  }

  if ((value = [self delegateValueForSelector:
                      @selector(adWhirlTextColor)])) {
    [additional setObject:[self hexStringFromUIColor:(UIColor *)value]
                   forKey:@"color_text"];
  } else {
    [additional setObject:[self hexStringFromUIColor:adWhirlConfig.textColor]
                     forKey:@"color_text"];
  }

The problem is located in the AdMob adapter:

  // Set the frame for this view to match the bounds of the parent adWhirlView.
  GADBannerView *view =
  [[GADBannerView alloc] initWithFrame:adWhirlView.bounds];

This is a very lousy implementation since AdWhirl is lacking optional delegate methods here. Though this is pretty easy to fix. Simple use one of AdMobs banner sizes and everything will work:

  GADBannerView *view =
  //[[GADBannerView alloc] initWithFrame:adWhirlView.bounds];
[[GADBannerView alloc] initWithFrame:CGRectMake(0, 0, GAD_SIZE_468x60.width, GAD_SIZE_468x60.height)];

You probably want to fix colors too. There are two bugs concerning colors:

  • The AdMob adapter does use the proper delegate methods (adWhirlAdBackgroundColor,adWhirlTextColor). Although, he simply uses the background color for text.
  • If the color delegate methods are not implemented, the AdMob adapter does not fallback to the colors you defined in your config.

To fix this, simply locate the code related to colors (right at the beginning of getAd()) and replace it with:

  if ((value = [self delegateValueForSelector:
                      @selector(adWhirlAdBackgroundColor)])) {
    [additional setObject:[self hexStringFromUIColor:(UIColor *)value]
                  forKey:@"color_bg"];
  } else {
    [additional setObject:[self hexStringFromUIColor:adWhirlConfig.backgroundColor]
                     forKey:@"color_bg"];
  }

  if ((value = [self delegateValueForSelector:
                      @selector(adWhirlTextColor)])) {
    [additional setObject:[self hexStringFromUIColor:(UIColor *)value]
                   forKey:@"color_text"];
  } else {
    [additional setObject:[self hexStringFromUIColor:adWhirlConfig.textColor]
                     forKey:@"color_text"];
  }
じ违心 2025-01-08 02:50:03

我有同样的问题。
我有 adWhirl 和 iAd & AdMob 广告已启用,我的做法如下:
…………

CGSize adSize = [adWhirlView actualAdSize];
 ......
if (adSize.height==50){
 // this is AdMob ad, change x position

 } else {
 // iAd ad, leave by default
 }

I have the same problem.
I have adWhirl with iAd & AdMob ads enabled and I made like this:
........

CGSize adSize = [adWhirlView actualAdSize];
 ......
if (adSize.height==50){
 // this is AdMob ad, change x position

 } else {
 // iAd ad, leave by default
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文