PDA

View Full Version : Auto rotation doesn't work when using iOS6 for iPhone4S




mikezang
Sep 21, 2012, 10:44 AM
I found the autorotation doesn't work after upgraded to iOS6 on iPhone4S with same source, what I can do?



dejo
Sep 21, 2012, 01:59 PM
shouldAutorotateToInterfaceOrientation: is deprecated in iOS 6.0.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/doc/uid/TP40006926-CH3-SW23

(Deprecated in iOS 6.0. Override the supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods instead.)

Duncan C
Sep 21, 2012, 02:20 PM
shouldAutorotateToInterfaceOrientation: is deprecated in iOS 6.0.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/doc/uid/TP40006926-CH3-SW23

shouldAutorotateToInterfaceOrientation: is deprecated in iOS 6, it's true.

Deprecated methods are slated for future removal, but continue to work for some period of time.

That means that new applications should use the new way of doing things. However, if you implement that method, it's still called, and still does the right thing. (I just tested it to be sure.)

dejo
Sep 21, 2012, 03:24 PM
That means that new applications should use the new way of doing things. However, if you implement that method, it's still called, and still does the right thing. (I just tested it to be sure.)

Except shouldAutorotateToInterfaceOrientation: is no longer called when running under iOS 6. (I just tested it to be sure. :) )

Duncan C
Sep 21, 2012, 03:36 PM
Except shouldAutorotateToInterfaceOrientation: is no longer called when running under iOS 6. (I just tested it to be sure. :) )

--opening mouth, inserting foot--

I tested it on the iPhone 6.0 simulator, and could swear it was calling shouldAutorotateToInterfaceOrientation. However, I just tried it on my newly upgraded iPad, and you're right, it's not calling shouldAutorotateToInterfaceOrientation under iOS 6. This is news to me.

I think that if your app is built for iOS < 6.0, it still calls shouldAutorotateToInterfaceOrientation for compatibility, but if you build with the base SDK >= 6.0, it doesn't call it any more.

The good news is that the new method, supportedInterfaceOrientations, is quite simple to implement.

I think our company is going to release our newest app with both methods in place. Under iOS 5, the system will call shouldAutorotateToInterfaceOrientation like always. Under iOS 6 (and later) it will call supportedInterfaceOrientations instead.

mikezang
Sep 21, 2012, 05:50 PM
shouldAutorotateToInterfaceOrientation: is deprecated in iOS 6.0.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/doc/uid/TP40006926-CH3-SW23
I add code as below, but it looks like same as before, no rotation.. what happened?

- (BOOL)shouldAutorotate {
return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

xStep
Sep 21, 2012, 06:43 PM
--opening mouth, inserting foot--

I tested it on the iPhone 6.0 simulator, and could swear it was calling shouldAutorotateToInterfaceOrientation. However, I just tried it on my newly upgraded iPad, and you're right, it's not calling shouldAutorotateToInterfaceOrientation under iOS 6. This is news to me.

I think that if your app is built for iOS < 6.0, it still calls shouldAutorotateToInterfaceOrientation for compatibility, but if you build with the base SDK >= 6.0, it doesn't call it any more.

The good news is that the new method, supportedInterfaceOrientations, is quite simple to implement.

I think our company is going to release our newest app with both methods in place. Under iOS 5, the system will call shouldAutorotateToInterfaceOrientation like always. Under iOS 6 (and later) it will call supportedInterfaceOrientations instead.

I first found out about this via the newer iPad simulator. Believe I was targeting iOS 5 on that as that app needs to run on iOS 5. So it does or can show up there too.

Tried it last night on the iPhone 6 Simulator and targeted iOS 5. Think I have the same problem with my personal app. Tried this app on the iPhone 5 today. Same issue.

A guy at work has my app from the app store and is running iOS 6 on a 4s. It rotates just fine.

This whole rotation thing is darn ugly. One guy I know referred to it as a bug. Boy, I wish! Would have been nice if Apple at least hi-lited it more. Most deprecations don't hit so quickly.

Anyway, I've got some work todo. :eek:

Duncan C
Sep 21, 2012, 07:01 PM
I first found out about this via the newer iPad simulator. Believe I was targeting iOS 5 on that as that app needs to run on iOS 5. So it does or can show up there too.

Tried it last night on the iPhone 6 Simulator and targeted iOS 5. Think I have the same problem with my personal app. Tried this app on the iPhone 5 today. Same issue.

A guy at work has my app from the app store and is running iOS 6 on a 4s. It rotates just fine.

This whole rotation thing is darn ugly. One guy I know referred to it as a bug. Boy, I wish! Would have been nice if Apple at least hi-lited it more. Most deprecations don't hit so quickly.

Anyway, I've got some work todo. :eek:

I agree with your comment about Apple giving us more warning. I can't think of another case where a method is deprecated in a new OS release and dropped right then and there. Usually there's a transition period where the old method is deprecated but still supported.

Since reading this thread, I've been scrambling to get our app working right in all cases. Here's what I've found based on pretty extensive testing:

Under iOS < iOS 6, shouldAutorotateToInterfaceOrientation is always called. That's because the new supportedInterfaceOrientations method is only defined for iOS 6.

Under iOS 6 (and presumably later OS versions...):


If your app is written with a base SDK of 6.0, the OS assumes that you are "iOS 6 ready", and uses the new supportedInterfaceOrientations method. Your shouldAutorotateToInterfaceOrientation methods never get called. This is the "gotcha" edge case you have to watch out for. This case means that if you add ANY iOS 6 features to your app, or just update your app to handle the new Retina 4" displays, you need to add the new supportedInterfaceOrientations method to all your view controllers that have custom shouldAutorotateToInterfaceOrientation methods. If your app also runs under older OS versions, it still needs to keep the old shouldAutorotateToInterfaceOrientation method.

If your app is written with a base SDK of < iOS 6, then when you run it under iOS 6, the OS still calls the older shouldAutorotateToInterfaceOrientation method. That means that older non "iOS 6-aware" apps handle rotation like they did under iOS 5.

xStep
Sep 21, 2012, 07:04 PM
I add code as below, but it looks like same as before, no rotation.. what happened?

- (BOOL)shouldAutorotate {
return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}


I still have to 'get it' too. The docs for supportedInterfaceOrientations say; "When the user changes the device orientation, the system calls this method on the root view controller or the topmost presented view controller that fills the window."

So it would appear any view controllers that do not match that narrow definition do not get the call.

More to learn. ;)

Duncan C
Sep 21, 2012, 07:09 PM
I still have to 'get it' too. The docs for supportedInterfaceOrientations say; "When the user changes the device orientation, the system calls this method on the root view controller or the topmost presented view controller that fills the window."

So it would appear any view controllers that do not match that narrow definition do not get the call.

More to learn. ;)

Right. That sentence describes the "master" view controller that is in charge of the screen. If you have a parent/child view controller arrangement, the system will only ask the parent view controller for it's supported orientation.

It makes sense if you think it through. You really can't mix orientations when the content of different view controllers is visible. All view controllers need to follow the same orientation, and the root/parent view controller that has full-screen control is the one that should be in charge of supported orientations.

The app I'm working on use the parent/child view controller scheme that was added in iOS 5. However, in most cases, the parent view controller is just a shell and there is child view controller that manages the whole screen. For that case, I have the parent child view controller ask the "master" child view controller what orientations it supports, and forward that info to the system.

firewood
Sep 21, 2012, 08:25 PM
I add code as below, but it looks like same as before, no rotation.. what happened?

- (BOOL)shouldAutorotate {
return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

make sure you do this:


[window setRootViewController: yourViewController];

on your first or master full screen view controller. You may hunt through your controllers, and see which one calls the above methods, or have to subclass a nav controller if that's your base controller.

mikezang
Sep 22, 2012, 04:35 AM
make sure you do this:


[window setRootViewController: yourViewController];

on your first or master full screen view controller. You may hunt through your controllers, and see which one calls the above methods, or have to subclass a nav controller if that's your base controller.
Thank you very much, I got it!