Permalink
Browse files

Improve orientation detection

  • Loading branch information...
1 parent 0a8ddd1 commit 53ecb4c50a347ce316338a8fbfdcea9cfefb43a6 @moredip moredip committed Jan 19, 2012
Showing with 28 additions and 9 deletions.
  1. +0 −1 example/Controls/features/my_first.feature
  2. +28 −8 src/OrientationCommand.m
@@ -5,7 +5,6 @@ Feature:
Scenario:
Rotating the simulator for demonstration purposes
-Given I launch the app
Given the device is in landscape orientation
Given the device is in portrait orientation
Given the device is in landscape orientation
@@ -7,24 +7,44 @@
//
#import "OrientationCommand.h"
+#import "NSObject+SBJSON.h"
@implementation OrientationCommand
-- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
- NSString *orientationDescription = nil;
- switch ( [UIDevice currentDevice].orientation ) {
+- (NSString *)getOrientationDescriptionViaStatusBar{
+ if( UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) )
+ return @"portrait";
+ else
+ return @"landscape";
+}
+
+- (NSString *)getOrientationDescriptionViaDevice{
+ switch ( [UIDevice currentDevice].orientation ) {
case UIDeviceOrientationLandscapeRight:
case UIDeviceOrientationLandscapeLeft:
- orientationDescription = @"landscape";
- break;
+ return @"landscape";
case UIDeviceOrientationPortrait:
case UIDeviceOrientationPortraitUpsideDown:
- orientationDescription = @"portrait";
- break;
+ return @"portrait";
+ case UIDeviceOrientationFaceUp:
+ NSLog(@"Device orientation is face up");
+ //fall thru
+ case UIDeviceOrientationFaceDown:
+ NSLog(@"Device orientation is face down");
+ //fall thru
+ case UIDeviceOrientationUnknown:
+ NSLog(@"Device orientation is unknown");
+ //fall thru
default:
- orientationDescription = @"flat";
+ return nil;
}
+}
+
+- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
+ NSString *orientationDescription = [self getOrientationDescriptionViaDevice];
+ if( !orientationDescription )
+ orientationDescription = [self getOrientationDescriptionViaStatusBar];
NSDictionary *dom = [NSDictionary dictionaryWithObject:orientationDescription forKey:@"orientation"];
return [dom JSONRepresentation];

0 comments on commit 53ecb4c

Please sign in to comment.