views:

478

answers:

2
([UIDevice currentDevice].orientation);

using the above code in my app, all i get is 0 (unknown)

is there something thats going wrong here? Seems pretty straightforward

edit: more research led me to the problem with using device orientation early in the app, which I am doing. However when I instead use interfaceOrientation, it always returns 1 (portrait)

A: 

How do you know it's null? By logging the value?

The orientation property is a numeric value (enum), so you should make sure to log it as such:

NSLog("%d",[UIDevice currentDevice].orientation);
Philippe Leybaert
ok thats my fault for logging incorrectly, but it's still logging as 0 (which i believe is unknown). See revised Question
Brodie
+2  A: 

Are you seeing this in the simulator or on the device?

The Simulator seems to always return 0, regardless of it's orientation.

If you're seeing this on the device, have you made sure that you're calling

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

From the documentation:

You must call this method before attempting to get orientation data from the receiver.

Jasarien