0
votes


I'm looking for a way to get a reliable iPhone orientation.
The best way I've found so far is calling [[UIDevice currentDevice] orientation]. For some reason, it always returns 0 to me - although I called

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

on the app's didFinishLaunching. In addition, I've heard it provides a non-reliable value if the device is flat.

I've also seen that you can access [[UIApplication sharedApplication] statusBarOrientation], but that always returns me 1.
I will mention that although I can't seem to get right rotation, the views ( created by xibs ) all rotate correctly, but I need to check the rotation in code.

Can anybody recommend a reliable way to check this?

Tnx in advance!

EDIT: ok weirdest bug ever - on some views [UIApplication sharedApplication].statusBarOrientation does work, but on some returns always 1.

1

1 Answers

0
votes

If the views are indeed rotating correctly then you can just check the view's controller's orientation with:

viewController.interfaceOrientation

If this is not acceptable in your usage, this seems like a good starting place to use the accelerometer in order to find this information:

http://blog.sallarp.com/iphone-accelerometer-device-orientation/