Updated Branches: refs/heads/2.9.x fe49c0537 -> b7230b43b
CB-5189 - ios - Backport for v2.9.1 of CB-4930 (InAppBrowser) Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/b7230b43 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/b7230b43 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/b7230b43 Branch: refs/heads/2.9.x Commit: b7230b43b545e6624d6dfa7361c7d7edde114d53 Parents: fe49c05 Author: Shazron Abdullah <[email protected]> Authored: Wed Oct 23 17:20:47 2013 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Wed Oct 23 17:20:47 2013 -0700 ---------------------------------------------------------------------- CordovaLib/Classes/CDVInAppBrowser.h | 8 ++--- CordovaLib/Classes/CDVInAppBrowser.m | 59 ++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/b7230b43/CordovaLib/Classes/CDVInAppBrowser.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h index 248274a..059edb0 100644 --- a/CordovaLib/Classes/CDVInAppBrowser.h +++ b/CordovaLib/Classes/CDVInAppBrowser.h @@ -17,10 +17,10 @@ under the License. */ -#import "CDVPlugin.h" -#import "CDVInvokedUrlCommand.h" -#import "CDVScreenOrientationDelegate.h" -#import "CDVWebViewDelegate.h" +#import <Cordova/CDVPlugin.h> +#import <Cordova/CDVInvokedUrlCommand.h> +#import <Cordova/CDVScreenOrientationDelegate.h> +#import <Cordova/CDVWebViewDelegate.h> @class CDVInAppBrowserViewController; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/b7230b43/CordovaLib/Classes/CDVInAppBrowser.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m index 2dfe2ce..5711e76 100644 --- a/CordovaLib/Classes/CDVInAppBrowser.m +++ b/CordovaLib/Classes/CDVInAppBrowser.m @@ -18,9 +18,9 @@ */ #import "CDVInAppBrowser.h" -#import "CDVPluginResult.h" -#import "CDVUserAgentUtil.h" -#import "CDVJSON.h" +#import <Cordova/CDVPluginResult.h> +#import <Cordova/CDVUserAgentUtil.h> +#import <Cordova/CDVJSON.h> #define kInAppBrowserTargetSelf @"_self" #define kInAppBrowserTargetSystem @"_system" @@ -32,6 +32,11 @@ #pragma mark CDVInAppBrowser +@interface CDVInAppBrowser () { + UIStatusBarStyle _previousStatusBarStyle; +} +@end + @implementation CDVInAppBrowser - (CDVInAppBrowser*)initWithWebView:(UIWebView*)theWebView @@ -59,6 +64,15 @@ self.callbackId = nil; } +- (BOOL) isSystemUrl:(NSURL*)url +{ + if ([[url host] isEqualToString:@"itunes.apple.com"]) { + return YES; + } + + return NO; +} + - (void)open:(CDVInvokedUrlCommand*)command { CDVPluginResult* pluginResult; @@ -72,6 +86,11 @@ if (url != nil) { NSURL* baseUrl = [self.webView.request URL]; NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL]; + + if ([self isSystemUrl:absoluteUrl]) { + target = kInAppBrowserTargetSystem; + } + if ([target isEqualToString:kInAppBrowserTargetSelf]) { [self openInCordovaWebView:absoluteUrl withOptions:options]; } else if ([target isEqualToString:kInAppBrowserTargetSystem]) { @@ -101,6 +120,7 @@ } } + _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options]; [self.inAppBrowserViewController showLocationBar:browserOptions.location]; @@ -141,8 +161,13 @@ } if (! browserOptions.hidden) { + + UINavigationController* nav = [[UINavigationController alloc] + initWithRootViewController:self.inAppBrowserViewController]; + nav.navigationBarHidden = YES; + if (self.viewController.modalViewController != self.inAppBrowserViewController) { - [self.viewController presentModalViewController:self.inAppBrowserViewController animated:YES]; + [self.viewController presentModalViewController:nav animated:YES]; } } [self.inAppBrowserViewController navigateTo:url]; @@ -152,7 +177,13 @@ { if ([self.inAppBrowserViewController isViewLoaded] && self.inAppBrowserViewController.view.window) return; - [self.viewController presentModalViewController:self.inAppBrowserViewController animated:YES]; + + _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; + + UINavigationController* nav = [[UINavigationController alloc] + initWithRootViewController:self.inAppBrowserViewController]; + nav.navigationBarHidden = YES; + [self.viewController presentModalViewController:nav animated:YES]; } - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options @@ -348,6 +379,10 @@ // Don't recycle the ViewController since it may be consuming a lot of memory. // Also - this is required for the PDF/User-Agent bug work-around. self.inAppBrowserViewController = nil; + + if (IsAtLeastiOSVersion(@"7.0")) { + [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; + } } @end @@ -618,6 +653,11 @@ [CDVUserAgentUtil releaseLock:&_userAgentLockToken]; [super viewDidUnload]; } + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} - (void)close { @@ -660,6 +700,15 @@ { [self.webView goForward]; } + +- (void)viewWillAppear:(BOOL)animated +{ + if (IsAtLeastiOSVersion(@"7.0")) { + [[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]]; + } + + [super viewWillAppear:animated]; +} #pragma mark UIWebViewDelegate
