iOS 6 Crashes on Device Rotation [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
THIS IS NOT A DUPLICATE QUESTION. A final working solution has NOT been provided yet. Please do not CLOSE this question until I have accepted an answer or found and provided my own solution for this. Thanks!
==================================================================
Using Xcode 4.5.1, I have a tab-bar app with 5 tabs in it. Each tab contains a UINavigationController. The entire App thus needs to be viewed in Portrait mode with the exception of one sole ViewController - a "modal" VC that opens in full screen and that's intended to be viewed in Landscape mode.
This worked perfectly well in iOS5 - I simply used the following code in that one particular ViewController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But now the App crashes, and gives this error:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',
reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
Any suggestions?

Kindly check the What version xcode you used.
You used XCODE 4.5: shouldAutorotateToInterfaceOrientation delegate Depreciated.
You use following lines in your project.
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

You need to use this to avoid iOS6 crash..
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown; //Getting error here? then update ur xcode to 4.5+
}
#endif

Remember one thing. In iOS 6
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
is deprecated.
You cannot use it in iOS 6. For supporting different interface orientation in viewControllers of a UINavigationController you need to subclass the UINavigationController or make a Category of it.

Code looks OK. it Should not have crashed for just that methods.
problem coud be in another part of code.
However ,here i would like to tell you.
Above shouldAutorotateToInterfaceOrientation methods orientation methods has deprecated in iOS 6.
if you want to know more how to fix orientation issue
you should take a look of this

Related

rotation issue in ios 6

I've looked everywhere, Yet I cant find a solution for this annoying rotation issue in iOS 6.
for some reason, I cant get the rotation methods in iOS 6 to work. they are not even called.
for example:
if I want to keep a view in portrait mode in iOS 5, I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I learned that the new method in iOS 6 should be:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
I've also try to add:
-(BOOL)shouldAutorotate
{
return NO;
}
but it dosent work at all.
please help!
If you have all that it should be as simple as setting the supported orientations in the Info.plist as well as in your controllers. You can do this through the Summary tab on your project target.

What are the changes in ios 6 as compare to previous versions of xcode?

I was build an app in ios 4.1 but now i am using ios 6 to build it but there are problems in pushviewcontroller and orientation methods. So can any one tell me what are the changes have brought in ios 6?
I think that best solution is to stick to official apple documentation. So according to that I use following methods and everything is working very well on iOS 5 and 6. In all of your ViewControllers override following methods.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Methods for iOS 6, first method returns supported orientation mask (as their name indicate), you can change it into Landscape or what suites you best.
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ...
}
second one thats tells your VC which is preferred interface orientation when VC is going to be displayed.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ...
}
This solution is working

IOS 6 view rotation issue [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Autorotate in iOS 6 has strange behaviour
I have issue with IOS 6, the display show up as portrait and not as landscape.
I am using both real and simulator device, if I build the game on 5.1 simulator the view is properly presented if I am using simulator version 6 or the real device with version 6 the view is get portrait view.
Here is my code.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight )
return YES;
Any idea how to solve such issue?
Thanks
ER
ShouldAutoRotation does not work anymore for iOS 6. Use supportedInterfaceOrientations instead.
You can get more information here: http://dhilipsiva.blogspot.com/2012/07/ios-6-ui-interface-orientation.html
Hope this helps.
The method shouldAutorotateToInterfaceOrientation has been deprecated for iOS 6. It has been replaced with the following:
- (BOOL)shouldAutoRotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
Also, there's a VERY important detail to make this work. In your AppDelegate, make sure you change the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window setRootViewController:<your main view controller here>];
}
If you're using [self.window addSubview:self.mainViewController.view], it won't work.
If you want to support iOS 5 as well as iOS 6, leave shouldAutorotateToInterfaceOrientation in your code; just know that it won't be called on iOS6 devices.
The example #Simon gave should be able to coexist peacefully with your original code, with either operating system calling its applicable method. I was able to implement something similar in my app, but I used the project settings to set up autorotation for iOS 6 and just left my shouldAutorotateToInterfaceOrientation alone to make the app compatible with iOS 5 too.

Keyboard is upside down in UIViewController

I'm trying to get my app updated to work with the new iPhone 5, and some of my views are dropping the keyboard down from the top of the view instead of the bottom. Here's an image to better illustrate:
This worked before iOS 6.0, so I'm guessing it must be something in the new API that is causing this bug to shine. I am using the following code to support orientations in the UIVeiwController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
Has anyone else seen a similar problem? Thanks!
I have tried to replicate your issue but it works good for me on iOS6. My suggestion might be not very helpful but review that delegate, the synthesize and all the features match.
I found the answer at this question. My problem was fixed by changing one line of code where I was setting up my root UI view controller.
Changing this line:
[window addSubview:viewController.view];
to this:
[window setRootViewController:viewController];
Andrew, I also find that the method shouldAutoROtateToInterfaceOrientation was deprecated in iOS 6.
Anyways, I saw you solved your issue.

How to restrict my app to landscape mode?

I have my iPad application created using the SplitView template.
I wonder what is the best way to restrict my application to landscape mode?
I have tried overriding shouldAutorotateToInterfaceOrientation: method in DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
but 4.2 GM is still buggy and it fails to show the controller view. What other choices do I have?
Thanks in advance.
UPDATE1
I have already filed a bug report:
Bug ID #8620135
My app is almost finished and I have to find a work-arround since I don't think they are going to solve this before 4.2 officially comes out (GM is already out!)
In order to recreate the bug, just use SplitView template and override above method in any of the UIViewControllers (RootViewController or DetailViewControllers)
UPDATE2
I have found a work-around. (See UPDATE3 for the complete work-around)
Set UISupportedInterfaceOrientations only to support Landscape , this will force the app to start in landscape mode allowing DetailViewController to start correctly(hence shown correctly)
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
But if you rotate the device, it turns Portrait mode!!!, so is still necessary to override shouldAutorotateToIntercafeOrientation: as above
Discussion:
If this wouldn't be a bug I would expect a warning or execution error, exception or something when starting the app in a orientation that is not supported by the view controller. Besides, why only DetailViewController does not show? If this would be specification, then RootViewController should also fail to load then. Don't you think?
thanks for you help... ;)
UPDATE3
After further tests I have realized that above work-around does not work in some cases. For example when starting the app when the device is in landscape won't work!.
The real problem seems to be that in iOS4.2GM UISplitViewController needs all its controllers have all rotations to be available at its load time. So is necessary to trick him so it loads in Landscape mode and then not allow him to rotate its view controllers.
So here is the new work-around for this annoying iBug.
Step1:
Set Info.plist like so:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Step2
Set a new flag in DetailViewController.m or .h (from SplitView Template)
BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//WORK-ARROUND: Bug ID# 8620135.
if (lockRotation) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}else{
return YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set NO here since this is called before shouldAutorotateToInterfaceOrientation method is called
lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
}
- (void)viewDidAppear:(BOOL)animated {
//set YES as soon as possible, but after shouldAutorotateToInterfaceOrientation method was called
lockRotation = YES; //WORK-ARROUND: Bug ID# 8620135.
[super viewDidAppear:animated];
}
IMPORTANT NOTE:
Please note that this bug only appears when the UISplitViewController is loaded and not everytime
the its view appears. Hence, to see this bug make sure the app was terminated before.
I asked a question with a bounty of 500 that seems to be the same thing you're facing.
From my limited experience it is much easier to make a landscape-only iPhone app than a landscape-only iPad app. I'm not sure why there is any difference, but the steps Apple says to take to make it landscape-only do not work on their own.
Try this (it works):
-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
}
else
{
return NO;
}
}
Check out this iPhone app in landscape mode, if you haven't already. I was going to suggest simply adding UISupportedInterfaceOrientations to your Info.plist and specifying the two landscape orientations. But, apparently, this is not sufficient, according to answers to cited question.
I believe this is a BUG, I faced this problem also. It is something to do with
UIInterfaceOrientationLandscapeLeft
To replicate this situation:
1) Create a new iPad project using UISplitViewController template
2) Edit info.plist
Supported interface orientations
-Landscape (left home button)
-Landscape (right home button)
3) DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// return YES;
NSLog(#"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
4) Run it....You will see a blank black view. and no matter how you turn. "UIInterfaceOrientationLandscapeLeft" never detected.
By the way, nacho4d's adding BOOL check work-around is working. Thumbs UP :)