1

Views in my app are portrait only - my view controllers and the root view controller both ensure that they only rotate to portrait orientations using both shouldAutorotateToInterfaceOrientation: and supportedInterfaceOrientations in order to support both iOS 5 and iOS 6. I've added an iAd banner to a view, and it appears correctly at the top of the screen. When I tap it to see a test ad on the iPad, the test ad appears in lanscape, which I expect - I understand iAds may be in any orientation. But when I close the ad my views are in landscape, both the view with the banner and the view of the root view controller. They rotate back to portrait and stay there when I rotate the device.

How can I prevent iAds from rotating my view, or make my views return to portrait when the iAd closes?

Edit: I've also tried using application:supportedInterfaceOrientationsForWindow: and setting shouldAutoRotate to true - neither solves the problem.

Edit again: I've still had no luck. Here's a project with a fairly minimal view controller implementation that shows the bug I'm experiencing - any help is appreciated!

Luke
  • 7,110
  • 6
  • 45
  • 74
  • a couple of things for clarity ... (1) i think you are trying to make the point that you are trying to cover both iOS 5 and iOS 6, but just in case ... from the iOS SDK release notes, in iOS 6, shouldAutoRotateToInterfaceOrientation: is deprecated. (2) you could skip the implementation of those by instead implementing application:supportedInterfaceOrientationsForWindow: ... see the documentation for how overrides for this work; (3) if you don't do (2) you may have to also implement shouldAutorotate to allow rotation back to portrait when coming out of a landscape iAd. – john.k.doe Mar 26 '13 at 23:25
  • Thanks, tried a few new things and edited my question to clarify. – Luke Mar 27 '13 at 03:17
  • @Luke, have you tried setting the orientation of iAd to ascertain orientation (ios5) and also set the resizing mask (iOS 6) in the ShouldAutorotate method? You can do that by adding a if statement for both iOS in ther and see if that works for you. I have tried this method before and it has worked in keeping the orientation of iad also in addition in banner did finish method you can set the orientation of the view to be of your desired one after the add lunches or finished. Just a though that might help.:) – Adrian P Mar 31 '13 at 13:11
  • @CodeMonkey I'm not sure how to set the orientation of the iAd or set its resizing mask - would you mind showing me some code? – Luke Mar 31 '13 at 14:14

3 Answers3

0

I would try 2 things. First set the "Supported interface orientations" in your app's Target configuration (Summary).

Then for each view in your interface builder, under the simulated metrics (4 tab on the properties panel) make sure Portrait orientation is selected. If you have "inferred" selected, then it will take the previous screen orientation when it displays itself.

Pochi
  • 13,391
  • 3
  • 64
  • 104
0

Solved. My secondary view controller had to be a child view controller of the main one.

Luke
  • 7,110
  • 6
  • 45
  • 74
0

I thought i'd just push an update as i got this fixed finally, this works on iOS 8 and 9, first up register the app to track device orientation.

AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    return YES;
}

Now when the advert finishes displaying you can check the device orientation and force it back to portrait.

-(void)bannerViewActionDidFinish:(ADBannerView *)banner{

            UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

            if (UIDeviceOrientationIsLandscape(orientation)) {

                NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
                [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
            }

            //NSLog(@"iAD actions finished");
    }
SmokersCough
  • 967
  • 7
  • 22