Reputation: 923
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
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
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