forked from moredip/Frank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrientationCommand.m
53 lines (45 loc) · 1.56 KB
/
OrientationCommand.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// OrientationCommand.m
// Chase.Mobi
//
// Created by Pete Hodgson on 9/21/10.
// Copyright 2010 ThoughtWorks. See NOTICE file for details.
//
#import "OrientationCommand.h"
#import "NSObject+SBJSON.h"
@implementation OrientationCommand
- (NSString *)getOrientationDescriptionViaStatusBar{
if( UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) )
return @"portrait";
else
return @"landscape";
}
- (NSString *)getOrientationDescriptionViaDevice{
switch ( [UIDevice currentDevice].orientation ) {
case UIDeviceOrientationLandscapeRight:
case UIDeviceOrientationLandscapeLeft:
return @"landscape";
case UIDeviceOrientationPortrait:
case UIDeviceOrientationPortraitUpsideDown:
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:
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];
}
@end