15

I am trying to figure out what orientation the iphone has in the simulator and instead of giving it to me using the UIDevice orientation property I just get UIDeviceOrientationUnknown.

Does this property not work in the simulator? What could be the possible reason for this happening?

I am using opengl es

Mel
  • 2,055
  • 2
  • 26
  • 45

2 Answers2

46

You can also use:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];  

which works even without calling beginGeneratingDeviceOrientationNotifications.

Chintan Patel
  • 3,175
  • 3
  • 30
  • 36
12

first of all, from the documentation about orientation property of UIDevice instance

The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.

and yes, it will work only on the real device. but you can use, for example, this accelerometer simulator.

Morion
  • 10,495
  • 1
  • 24
  • 33
  • Sorry but no, it does not work only on the real device. I just loggued a landscape device orientation on the simulator and then a portrait one. Maybe it was not the case with previous SDK versions... (I'm on 3.1.3) I guess we can use -[UIApplication statusBarOrientation] to determine the current interface orientation (except if we manually change the status bar orientation). And I'm not sure if this will work with a hidden status bar. – Unfalkster Mar 31 '10 at 23:19
  • 1
    This works on the simulator, just not all the time. Use [[UIApplication sharedApplication] statusBarOrientation], as mentioned in the answer below. – Greg Maletic Jun 19 '12 at 21:55