diff --git a/src/ios/CDVViewController+UpdateSupportedOrientations.h b/src/ios/CDVViewController+UpdateSupportedOrientations.h new file mode 100644 index 0000000..cdd4073 --- /dev/null +++ b/src/ios/CDVViewController+UpdateSupportedOrientations.h @@ -0,0 +1,31 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#import + +@interface CDVViewController (UpdateSupportedOrientations) + +- (void)updateSupportedOrientations:(NSArray *)orientations; + +@end diff --git a/src/ios/CDVViewController+UpdateSupportedOrientations.m b/src/ios/CDVViewController+UpdateSupportedOrientations.m new file mode 100644 index 0000000..03421b7 --- /dev/null +++ b/src/ios/CDVViewController+UpdateSupportedOrientations.m @@ -0,0 +1,35 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +#import "CDVViewController+UpdateSupportedOrientations.h" + +@implementation CDVViewController (UpdateSupportedOrientations) + +- (void)updateSupportedOrientations:(NSArray *)orientations { + + [self setValue:orientations forKey:@"supportedOrientations"]; + +} + +@end diff --git a/src/ios/YoikScreenOrientation.h b/src/ios/YoikScreenOrientation.h index a90b9c6..dd23599 100644 --- a/src/ios/YoikScreenOrientation.h +++ b/src/ios/YoikScreenOrientation.h @@ -20,6 +20,7 @@ */ #import +#import @interface YoikScreenOrientation : CDVPlugin diff --git a/src/ios/YoikScreenOrientation.m b/src/ios/YoikScreenOrientation.m index e87367c..9ffe8fa 100644 --- a/src/ios/YoikScreenOrientation.m +++ b/src/ios/YoikScreenOrientation.m @@ -20,6 +20,7 @@ */ #import "YoikScreenOrientation.h" +#import "CDVViewController+UpdateSupportedOrientations.h" @implementation YoikScreenOrientation @@ -61,9 +62,8 @@ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; // SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation - // HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately - // This has been changed substantially since iOS8 broke it... - ForcedViewController *vc = [[ForcedViewController alloc] init]; + // HACK: Force rotate by changing the view hierarchy. + ForcedViewController *vc = [[ForcedViewController alloc] init]; vc.calledWith = orientationIn; // backgound should be transparent as it is briefly visible @@ -78,12 +78,7 @@ #endif dispatch_async(dispatch_get_main_queue(), ^{ - [self.viewController presentViewController:vc animated:NO completion:^{ - // added to support iOS8 beta 5, @see issue #19 - dispatch_after(0, dispatch_get_main_queue(), ^{ - [self.viewController dismissViewControllerAnimated:NO completion:nil]; - }); - }]; + [self.viewController presentViewController:vc animated:NO completion:nil]; }); }]; @@ -93,6 +88,20 @@ @implementation ForcedViewController +-(void) viewDidAppear:(BOOL)animated { + CDVViewController *presenter = (CDVViewController*)self.presentingViewController; + + if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) { + [presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationPortrait]]]; + + } else if([self.calledWith rangeOfString:@"landscape"].location != NSNotFound) { + [presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]]]; + } else { + [presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], [NSNumber numberWithInt:UIInterfaceOrientationPortrait]]]; + } + [presenter dismissViewControllerAnimated:NO completion:nil]; +} + - (UIInterfaceOrientationMask) supportedInterfaceOrientations { if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {