Jaume
Jaume

Reputation: 923

iOS return landscape orientation when is Portrait

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

Upvotes: 0

Views: 1098

Answers (2)

rooftop
rooftop

Reputation: 3027

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?

Upvotes: 0

Rob Napier
Rob Napier

Reputation: 299345

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.

Upvotes: 1

Related Questions