Merge pull request #24 from dnfield/master

CB-13405: (ios) Go to last used orientation before locking when unlocking screen on iOS
This commit is contained in:
Vishal Mishra
2017-12-12 10:41:05 -08:00
committed by GitHub
2 changed files with 30 additions and 10 deletions
+5 -1
View File
@@ -24,7 +24,11 @@
#import <Cordova/CDVViewController.h>
@interface CDVOrientation : CDVPlugin
{}
{
@protected
BOOL _isLocked;
UIInterfaceOrientation _lastOrientation;
}
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
+25 -9
View File
@@ -51,21 +51,37 @@
SEL selector = NSSelectorFromString(@"setSupportedOrientations:");
if([vc respondsToSelector:selector]) {
((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
if (orientationMask != 15 || [UIDevice currentDevice] == nil) {
((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
}
if ([UIDevice currentDevice] != nil){
NSNumber *value = nil;
if(orientationMask == 8 || orientationMask == 12) {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
} else if (orientationMask == 4){
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
} else if (orientationMask == 1 || orientationMask == 3) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
} else if (orientationMask == 2) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
if (orientationMask != 15) {
if (!_isLocked) {
_lastOrientation = [UIApplication sharedApplication].statusBarOrientation;
}
if(orientationMask == 8 || orientationMask == 12) {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
} else if (orientationMask == 4){
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
} else if (orientationMask == 1 || orientationMask == 3) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
} else if (orientationMask == 2) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
}
} else {
if (_lastOrientation != UIInterfaceOrientationUnknown) {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:_lastOrientation] forKey:@"orientation"];
((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
[UINavigationController attemptRotationToDeviceOrientation];
}
}
if (value != nil) {
_isLocked = true;
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
} else {
_isLocked = false;
}
}