【问题标题】:Correct way to implement iAd in iOs 7 iPhone app in iPad在 iPad 的 iOs 7 iPhone 应用程序中实施 iAd 的正确方法
【发布时间】:2014-01-06 16:25:29
【问题描述】:

我的 iAd 在 iPad(模拟器或真机)上以横幅视图和点击时在 iAd 视图中被放大时遇到了问题。它在 iPhone 上运行良好,只是在 iPad 上不行(当自动缩放时)。

iPhone 应用本身非常简单,布局合理,仅支持纵向。

我知道 currentContentSizeIdentifier 已被弃用,但是在 iOS 7 后的世界中如何处理这个问题?我试过使用

self.canDisplayBannerAds=YES:

...但是还没有弄清楚在使用这个方法时如何设置委托。

这是我的 viewDidLoad 的开始,我在其中添加 iAd 横幅并将其定位到视图的底部。

 - (void)viewDidLoad
{
    [super viewDidLoad];
  //add iAd banner
    CGRect myView=self.view.frame;  //get the view frame
  //offset the banner to place it at bottom of view
    CGRect bannerFrame= CGRectOffset(myView, 0, myView.size.height);
  //Create the bannerView
    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:bannerFrame];
  //yes, deprecated, but what to use now?
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    [self.view addSubview:adView];
    adView.delegate = self;
...

我很欣赏你在这件事上的智慧,一如既往......

【问题讨论】:

  • 你的应用是通用的还是 iphone 应用而 ipad 只是模拟 iphone(带框架)?

标签: iphone ipad ios7


【解决方案1】:

从 iOS 6 开始,Apple 决定制作所有 iAd 以适应整个屏幕宽度。所以你别无选择再改变它。在您的viewDidLoad 中使用:

// On iOS 6 ADBannerView introduces a new initializer, use it when available

if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)])
{
    _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
    _bannerView = [[ADBannerView alloc] init];
    _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
}
_bannerView.delegate = self;
[self.view addSubview:_bannerView];

并调整您的视图大小并为您的横幅提供正确的位置使用:

- (void)viewDidLayoutSubviews {
   CGRect contentFrame = self.view.bounds, bannerFrame = CGRectZero;

   // All we need to do is ask the banner for a size that fits into the layout area we are using.
   // At this point in this method contentFrame=self.view.bounds, so we'll use that size for the layout.
   bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];

   if (_bannerView.bannerLoaded) {
      contentFrame.size.height -= bannerFrame.size.height;
      bannerFrame.origin.y = contentFrame.size.height;
   } else {
      bannerFrame.origin.y = contentFrame.size.height;
   }
   _contentView.frame = contentFrame;
   _bannerView.frame = bannerFrame;
}

【讨论】:

  • 我有同样的问题,但对我来说这并没有解决任何问题。
  • 我的 iad 横幅有类似的东西,它只在 ipad 上被搞砸了。对此我很抱歉,但我不知道为什么,但我现在使用 admob,因为仅 iads 的填充率不是那么好。并且使用 admob 的 sdk 我集成了 iads 和谷歌广告。但真正奇怪的是,iads 现在看起来完全没问题!也许你们会试试这个:apps.admob.com
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-24
相关资源
最近更新 更多