diff --git a/src/ios/CDVInAppBrowser.h b/src/ios/CDVInAppBrowser.h index e643962..0ba07f1 100644 --- a/src/ios/CDVInAppBrowser.h +++ b/src/ios/CDVInAppBrowser.h @@ -63,7 +63,7 @@ @end -@interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate>{ +@interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate, CDVScreenOrientationDelegate>{ @private NSString* _userAgent; NSString* _prevUserAgent; @@ -92,4 +92,10 @@ - (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions; +@end + +@interface CDVInAppBrowserNavigationController : UINavigationController + +@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate; + @end \ No newline at end of file diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index 68675c5..aed735c 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -216,8 +216,9 @@ _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; - UINavigationController* nav = [[UINavigationController alloc] + CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc] initWithRootViewController:self.inAppBrowserViewController]; + nav.orientationDelegate = self.inAppBrowserViewController; nav.navigationBarHidden = YES; // Run later to avoid the "took a long time" log message. dispatch_async(dispatch_get_main_queue(), ^{ @@ -964,4 +965,37 @@ return obj; } +@end + +@implementation CDVInAppBrowserNavigationController : UINavigationController + +#pragma mark CDVScreenOrientationDelegate + +- (BOOL)shouldAutorotate +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotate)]) { + return [self.orientationDelegate shouldAutorotate]; + } + return YES; +} + +- (NSUInteger)supportedInterfaceOrientations +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) { + return [self.orientationDelegate supportedInterfaceOrientations]; + } + + return 1 << UIInterfaceOrientationPortrait; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) { + return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation]; + } + + return YES; +} + + @end