mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
StatusBar - remove dependence of UIViewControllerBasedStatusBarAppearance Info.plist key
This commit is contained in:
parent
ea57d604f5
commit
9c9a8ba983
@ -4,8 +4,6 @@ StatusBar
|
|||||||
> The `StatusBar` object provides some functions to customize the iOS StatusBar.
|
> The `StatusBar` object provides some functions to customize the iOS StatusBar.
|
||||||
|
|
||||||
The plugin reads the __StatusBarOverlaysWebView__ (boolean, defaults to true) and __StatusBarBackgroundColor__ (color hex string, defaults to #000000) values from config.xml.
|
The plugin reads the __StatusBarOverlaysWebView__ (boolean, defaults to true) and __StatusBarBackgroundColor__ (color hex string, defaults to #000000) values from config.xml.
|
||||||
|
|
||||||
For iOS 7, to use the statusbar style functions, you need the addition of a key in your Info.plist. See the Permissions section below.
|
|
||||||
|
|
||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
@ -34,11 +32,6 @@ Permissions
|
|||||||
<param name="ios-package" value="CDVStatusBar" onload="true" />
|
<param name="ios-package" value="CDVStatusBar" onload="true" />
|
||||||
</feature>
|
</feature>
|
||||||
|
|
||||||
#### [ProjectName]-Info.plist
|
|
||||||
|
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
|
||||||
<false/>
|
|
||||||
|
|
||||||
StatusBar.overlaysWebView
|
StatusBar.overlaysWebView
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
12
plugin.xml
12
plugin.xml
@ -28,21 +28,9 @@
|
|||||||
<preference name="StatusBarBackgroundColor" value="#000000" />
|
<preference name="StatusBarBackgroundColor" value="#000000" />
|
||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<!-- add this manually for now, crash bug - see https://issues.apache.org/jira/browse/CB-5012
|
|
||||||
<config-file target="*-Info.plist" parent="UIViewControllerBasedStatusBarAppearance" >
|
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
|
||||||
<false/>
|
|
||||||
</config-file>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<header-file src="src/ios/CDVStatusBar.h" />
|
<header-file src="src/ios/CDVStatusBar.h" />
|
||||||
<source-file src="src/ios/CDVStatusBar.m" />
|
<source-file src="src/ios/CDVStatusBar.m" />
|
||||||
|
|
||||||
<info>
|
|
||||||
Add this key and value to your project's Info.plist:
|
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
|
||||||
<false/>
|
|
||||||
</info>
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
BOOL _statusBarOverlaysWebView;
|
BOOL _statusBarOverlaysWebView;
|
||||||
@protected
|
@protected
|
||||||
UIView* _statusBarBackgroundView;
|
UIView* _statusBarBackgroundView;
|
||||||
|
@protected
|
||||||
|
BOOL _uiviewControllerBasedStatusBarAppearance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (atomic, assign) BOOL statusBarOverlaysWebView;
|
@property (atomic, assign) BOOL statusBarOverlaysWebView;
|
||||||
|
@ -24,6 +24,51 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import "CDVStatusBar.h"
|
#import "CDVStatusBar.h"
|
||||||
|
#import <objc/runtime.h>
|
||||||
|
#import <Cordova/CDVViewController.h>
|
||||||
|
|
||||||
|
static const void *kHideStatusBar = &kHideStatusBar;
|
||||||
|
static const void *kStatusBarStyle = &kStatusBarStyle;
|
||||||
|
|
||||||
|
@interface CDVViewController (StatusBar)
|
||||||
|
|
||||||
|
@property (nonatomic, retain) id sb_hideStatusBar;
|
||||||
|
@property (nonatomic, retain) id sb_statusBarStyle;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation CDVViewController (StatusBar)
|
||||||
|
|
||||||
|
@dynamic sb_hideStatusBar;
|
||||||
|
@dynamic sb_statusBarStyle;
|
||||||
|
|
||||||
|
- (id)sb_hideStatusBar {
|
||||||
|
return objc_getAssociatedObject(self, kHideStatusBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setSb_hideStatusBar:(id)newHideStatusBar {
|
||||||
|
objc_setAssociatedObject(self, kHideStatusBar, newHideStatusBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)sb_statusBarStyle {
|
||||||
|
return objc_getAssociatedObject(self, kStatusBarStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setSb_statusBarStyle:(id)newStatusBarStyle {
|
||||||
|
objc_setAssociatedObject(self, kStatusBarStyle, newStatusBarStyle, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) prefersStatusBarHidden {
|
||||||
|
return [self.sb_hideStatusBar boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
||||||
|
{
|
||||||
|
return (UIStatusBarStyle)[self.sb_statusBarStyle intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation CDVStatusBar
|
@implementation CDVStatusBar
|
||||||
|
|
||||||
@ -32,14 +77,6 @@
|
|||||||
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
|
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) checkInfoPlistKey
|
|
||||||
{
|
|
||||||
NSNumber* uiviewControllerBasedStatusBarAppearance = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"];
|
|
||||||
if (uiviewControllerBasedStatusBarAppearance == nil || [uiviewControllerBasedStatusBarAppearance boolValue]) {
|
|
||||||
NSLog(@"ERROR: To use the statusbar plugin, in your app's Info.plist, you need to add a 'UIViewControllerBasedStatusBarAppearance' key with a value of <false/>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
|
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
|
||||||
{
|
{
|
||||||
if ([keyPath isEqual:@"statusBarHidden"]) {
|
if ([keyPath isEqual:@"statusBarHidden"]) {
|
||||||
@ -52,6 +89,12 @@
|
|||||||
|
|
||||||
- (void)pluginInitialize
|
- (void)pluginInitialize
|
||||||
{
|
{
|
||||||
|
BOOL isiOS7 = (IsAtLeastiOSVersion(@"7.0"));
|
||||||
|
|
||||||
|
// init
|
||||||
|
NSNumber* uiviewControllerBasedStatusBarAppearance = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"];
|
||||||
|
_uiviewControllerBasedStatusBarAppearance = (uiviewControllerBasedStatusBarAppearance == nil || [uiviewControllerBasedStatusBarAppearance boolValue]) && isiOS7;
|
||||||
|
|
||||||
// observe the statusBarHidden property
|
// observe the statusBarHidden property
|
||||||
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
|
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
|
||||||
|
|
||||||
@ -126,6 +169,29 @@
|
|||||||
self.statusBarOverlaysWebView = [value boolValue];
|
self.statusBarOverlaysWebView = [value boolValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) refreshStatusBarAppearance
|
||||||
|
{
|
||||||
|
SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate");
|
||||||
|
if ([self.viewController respondsToSelector:sel]) {
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
||||||
|
[self.viewController performSelector:sel withObject:nil];
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setStyleForStatusBar:(UIStatusBarStyle)style
|
||||||
|
{
|
||||||
|
if (_uiviewControllerBasedStatusBarAppearance) {
|
||||||
|
CDVViewController* vc = (CDVViewController*)self.viewController;
|
||||||
|
vc.sb_statusBarStyle = [NSNumber numberWithInt:style];
|
||||||
|
[self refreshStatusBarAppearance];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
[[UIApplication sharedApplication] setStatusBarStyle:style];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) setStatusBarStyle:(NSString*)statusBarStyle
|
- (void) setStatusBarStyle:(NSString*)statusBarStyle
|
||||||
{
|
{
|
||||||
// default, lightContent, blackTranslucent, blackOpaque
|
// default, lightContent, blackTranslucent, blackOpaque
|
||||||
@ -144,26 +210,22 @@
|
|||||||
|
|
||||||
- (void) styleDefault:(CDVInvokedUrlCommand*)command
|
- (void) styleDefault:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
[self checkInfoPlistKey];
|
[self setStyleForStatusBar:UIStatusBarStyleDefault];
|
||||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) styleLightContent:(CDVInvokedUrlCommand*)command
|
- (void) styleLightContent:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
[self checkInfoPlistKey];
|
[self setStyleForStatusBar:UIStatusBarStyleLightContent];
|
||||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command
|
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
[self checkInfoPlistKey];
|
[self setStyleForStatusBar:UIStatusBarStyleBlackTranslucent];
|
||||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command
|
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
[self checkInfoPlistKey];
|
[self setStyleForStatusBar:UIStatusBarStyleBlackOpaque];
|
||||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command
|
- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command
|
||||||
@ -202,6 +264,19 @@
|
|||||||
|
|
||||||
[self _backgroundColorByHexString:value];
|
[self _backgroundColorByHexString:value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) hideStatusBar
|
||||||
|
{
|
||||||
|
if (_uiviewControllerBasedStatusBarAppearance) {
|
||||||
|
CDVViewController* vc = (CDVViewController*)self.viewController;
|
||||||
|
vc.sb_hideStatusBar = [NSNumber numberWithBool:YES];
|
||||||
|
[self refreshStatusBarAppearance];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
UIApplication* app = [UIApplication sharedApplication];
|
||||||
|
[app setStatusBarHidden:YES];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) hide:(CDVInvokedUrlCommand*)command
|
- (void) hide:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
@ -210,7 +285,7 @@
|
|||||||
if (!app.isStatusBarHidden)
|
if (!app.isStatusBarHidden)
|
||||||
{
|
{
|
||||||
self.viewController.wantsFullScreenLayout = YES;
|
self.viewController.wantsFullScreenLayout = YES;
|
||||||
[app setStatusBarHidden:YES];
|
[self hideStatusBar];
|
||||||
|
|
||||||
if (IsAtLeastiOSVersion(@"7.0")) {
|
if (IsAtLeastiOSVersion(@"7.0")) {
|
||||||
[_statusBarBackgroundView removeFromSuperview];
|
[_statusBarBackgroundView removeFromSuperview];
|
||||||
@ -220,7 +295,19 @@
|
|||||||
|
|
||||||
self.viewController.view.frame = bounds;
|
self.viewController.view.frame = bounds;
|
||||||
self.webView.frame = bounds;
|
self.webView.frame = bounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) showStatusBar
|
||||||
|
{
|
||||||
|
if (_uiviewControllerBasedStatusBarAppearance) {
|
||||||
|
CDVViewController* vc = (CDVViewController*)self.viewController;
|
||||||
|
vc.sb_hideStatusBar = [NSNumber numberWithBool:NO];
|
||||||
|
[self refreshStatusBarAppearance];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
UIApplication* app = [UIApplication sharedApplication];
|
||||||
|
[app setStatusBarHidden:NO];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +320,7 @@
|
|||||||
BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));
|
BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));
|
||||||
self.viewController.wantsFullScreenLayout = isIOS7;
|
self.viewController.wantsFullScreenLayout = isIOS7;
|
||||||
|
|
||||||
[app setStatusBarHidden:NO];
|
[self showStatusBar];
|
||||||
|
|
||||||
if (isIOS7) {
|
if (isIOS7) {
|
||||||
CGRect bounds = [[UIScreen mainScreen] bounds];
|
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||||
|
Loading…
Reference in New Issue
Block a user