From 114aeef0bb79478098669594e7207357ffcc7644 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 5 Oct 2017 14:13:26 -0400 Subject: [PATCH 1/2] CB-13405: (ios) Screen unlock bug fix --- src/ios/CDVOrientation.h | 5 ++++- src/ios/CDVOrientation.m | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ios/CDVOrientation.h b/src/ios/CDVOrientation.h index 48166a3..7e38d6f 100644 --- a/src/ios/CDVOrientation.h +++ b/src/ios/CDVOrientation.h @@ -24,7 +24,10 @@ #import @interface CDVOrientation : CDVPlugin -{} +{ +@protected + UIInterfaceOrientation _lastOrientation; +} - (void)screenOrientation:(CDVInvokedUrlCommand *)command; diff --git a/src/ios/CDVOrientation.m b/src/ios/CDVOrientation.m index c7704e4..a96b02d 100644 --- a/src/ios/CDVOrientation.m +++ b/src/ios/CDVOrientation.m @@ -55,17 +55,25 @@ 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) { + _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 != nil) { + value = [NSNumber numberWithInt:_lastOrientation]; + } } if (value != nil) { [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + [UINavigationController attemptRotationToDeviceOrientation]; } } From b4db5e2796abf7a773b8e644f55e9457c221693a Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 5 Oct 2017 15:16:07 -0400 Subject: [PATCH 2/2] CB-13405: (ios) undo lock when resetting --- src/ios/CDVOrientation.h | 1 + src/ios/CDVOrientation.m | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ios/CDVOrientation.h b/src/ios/CDVOrientation.h index 7e38d6f..6bdd4d4 100644 --- a/src/ios/CDVOrientation.h +++ b/src/ios/CDVOrientation.h @@ -26,6 +26,7 @@ @interface CDVOrientation : CDVPlugin { @protected + BOOL _isLocked; UIInterfaceOrientation _lastOrientation; } diff --git a/src/ios/CDVOrientation.m b/src/ios/CDVOrientation.m index a96b02d..0152680 100644 --- a/src/ios/CDVOrientation.m +++ b/src/ios/CDVOrientation.m @@ -51,12 +51,16 @@ 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 != 15) { - _lastOrientation = [UIApplication sharedApplication].statusBarOrientation; + if (!_isLocked) { + _lastOrientation = [UIApplication sharedApplication].statusBarOrientation; + } if(orientationMask == 8 || orientationMask == 12) { value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; } else if (orientationMask == 4){ @@ -67,13 +71,17 @@ value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]; } } else { - if (_lastOrientation != nil) { - value = [NSNumber numberWithInt:_lastOrientation]; + 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"]; - [UINavigationController attemptRotationToDeviceOrientation]; + } else { + _isLocked = false; } }