iPhone应用程序中实现iAd的正确方法

iPhone应用程序中实现iAd的正确方法

本文介绍了在iPad中的iOs 7 iPhone应用程序中实现iAd的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,在横幅视图中显示我的iAds时,如果在iPad(模拟器或真实版本)上显示,iAds会在iAd视图中点亮。它在iPhone中工作正常,而不是在iPad中(自动缩放时)。

I'm having a problem where my iAds are being zoomed up when shown on an iPad (simulator or real) in both the banner view and, if clicked on, in the iAd view. It works fine in the iPhone, just not in the iPad (when auto zoomed).

iPhone应用程序本身非常简单,布局方面,只支持纵向方向。

The iPhone app itself is pretty simple, layout-wise, and only supports a portrait orientation.

我知道currentContentSizeIdentifier已被弃用,但是如何在帖子中解决这个问题iOS 7世界?我尝试过使用

I understand that currentContentSizeIdentifier is deprecated, but how does one deal with this in a post iOS 7 world? I've tried using

self.canDisplayBannerAds=YES:

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

... but haven't figured out how do set the delegate when using this method.

这是我的viewDidLoad的开头,我在其中添加了iAd横幅并将其放置在视图的底部。

Here's the beginning of my viewDidLoad, where I add the iAd banner and position it to the bottom of the view.

 - (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;
...

我一如既往地感谢你在这件事上的智慧...... / p>

I appreciate your wisdom in this matter, as always...

推荐答案

从iOS 6开始,Apple决定让所有iAd都适合整个屏幕宽度。所以你别无选择。在 viewDidLoad 中使用:

Since iOS 6, Apple decided to make all iAds to fit the entire screen width. so you have no choice to change that any more. In your viewDidLoad use:

// 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];

并调整视图大小并使横幅广告正确使用:

and to resize your view and give your banner the right position use:

- (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;
}

这篇关于在iPad中的iOs 7 iPhone应用程序中实现iAd的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:43