0

I am trying to control iAd size when starts from landscape or portrait. Problem is that device tells that is on landscape when is on portrait! How to handle it? Thank you

- (void)viewDidLoad
{

    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

    adView.delegate = self;

    if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

    [self.view addSubview:adView];

    [super viewDidLoad];
}
Jaume
  • 913
  • 2
  • 17
  • 31

2 Answers2

1

You almost always want to use [self interfaceOrientation] here.

Regarding why orientation doesn't work, note the docs:

The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
0

Are you sure it's telling you it's on landspace or simply not Portrait, as you if is setup to only recognize Portrait. It's possible that the simulator is returning nil, as mentioned in this thread: UIDevice currentDevice's "orientation" always null Are you using the simulator or a device?

Community
  • 1
  • 1
rooftop
  • 3,031
  • 1
  • 22
  • 33