Friday, 27 September 2013

How to make test with UIInterfaceOrientation enum values

How to make test with UIInterfaceOrientation enum values

I'm a little bit lost in the bitwise ;)
My goal is to retrieve the whole set of orientations supported by an
application and to test each result value to update a custom variable. My
problem is that I don't know how to make the comparison (I got a
conversion/test problem...)
First I read this article : Testing for bitwise Enum values But it doesn't
bring me the light...
Let say I have the following orientation declare for my application
(following is the log output for my variable supportedOrientations) :
supported orientations = ( UIInterfaceOrientationPortrait )
So my first attempt was to try some test on integer values but it does not
work (even if the application is declared to be in portrait mode the test
return 'false') :
NSArray *supportedOrientations = [[NSBundle mainBundle]
objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
NSLog(@"[supported orientations = %@", supportedOrientations);
// for clarity just make a test on the first orientation we found
if ((NSInteger)supportedOrientations[0] == UIInterfaceOrientationPortrait) {
NSLog(@"We detect Portrait mode!");
}
My second attempt was to try the bitwise thing but this time it always
return 'true' (even if the supported orientation is not
UIInterfaceOrientationPortrait). :
NSArray *supportedOrientations = [[NSBundle mainBundle]
objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
NSLog(@"[supported orientations = %@", supportedOrientations);
// for clarity just make a test on the first orientation we found
if ((NSInteger)supportedOrientations[0] | UIInterfaceOrientationPortrait)
{ // <-- I also test with UIInterfaceOrientationMaskPortrait but no more
success
NSLog(@"We detect Portrait mode!");
}
So my question is :
How to test the orientation in my case?
Is it a way to use a test by using a bitwise thing (using | operand)?

No comments:

Post a Comment