1
votes

I see a lot of questions about this subject but am unable to find a solution to the problem I am experiencing. I have created an iPad app that should be Landscape only - it works fine when ran on any os prior to iOS6 but on iOS6 the app opens in portrait view. This screenshot shows what I mean (sorry not a great explanation) http://s1342.beta.photobucket.com/user/designedbyria/media/ScreenShot2012-11-02at122113.png.html

I'm guessing the problem is somewhere in the below code, but I can't be sure. I have set the supported Interface Orientations to Landscape Left and Landscape Right only - but this has not worked. I have also taken a look at the questions here with no luck..

I am using xcode and cordova/phonegap

Interface orientation in iOS 6.0

Set orientation to landscape mode in xcode 4.5 GM IOS 6

iOS 6 apps - how to deal with iPhone 5 screen size?

Thanks in Advance!

/** * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up) / - (BOOL) application:(UIApplication)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions {
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]; NSString* invokeString = nil;

if (url && [url isKindOfClass:[NSURL class]]) {
    invokeString = [url absoluteString];      NSLog(@"iwill launchOptions = %@", url);
}    

CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;

CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];

self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;

// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];


if (UIDeviceOrientationUnknown == UIInterfaceOrientationLandscapeLeft) {
    // UIDevice isn't firing orientation notifications yet… go look at the status bar
    curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}

if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
    for (NSNumber *orient in self.viewController.supportedOrientations) {
        if ([orient intValue] == curDevOrientation) {
            forceStartupRotation = YES;
            break;
        }
    }
} 

if (forceStartupRotation) {
    NSLog(@"supportedOrientations: %@", self.viewController.supportedOrientations);
    // The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
    UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0]

intValue]; NSLog(@"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation); [[UIApplication sharedApplication] setStatusBarOrientation:newOrient];

}


[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];

return YES; }
2

2 Answers

3
votes

I had the same problem (but not using cordova/phonegap).

You have to set your view controller as a RootViewController in your appDelegate instead of just adding as a subview.

Replace in you appdelegate:

[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];

By

[self.window setRootViewController:self.viewController];
[self.window makeKeyAndVisible];
0
votes

You can use the delegate

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{
  return UIInterfaceOrientationLandscapeLeft;

}

Using this delegate and the application will be present in Landscape mode or any desired orientation mode.

Try it.