diff --git a/src/ios/CDVOrientation.h b/src/ios/CDVOrientation.h index 48166a3..6bdd4d4 100644 --- a/src/ios/CDVOrientation.h +++ b/src/ios/CDVOrientation.h @@ -24,7 +24,11 @@ #import @interface CDVOrientation : CDVPlugin -{} +{ +@protected + BOOL _isLocked; + UIInterfaceOrientation _lastOrientation; +} - (void)screenOrientation:(CDVInvokedUrlCommand *)command; diff --git a/src/ios/CDVOrientation.m b/src/ios/CDVOrientation.m index c7704e4..0152680 100644 --- a/src/ios/CDVOrientation.m +++ b/src/ios/CDVOrientation.m @@ -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; } }