Added statusbar preferences to plugin.xml

Removed Info.plist section in plugin xml due to crash: https://issues.apache.org/jira/browse/CB-5012
This commit is contained in:
Shazron Abdullah 2013-10-07 15:13:32 -07:00
parent 058c6b71cc
commit 690de48214
2 changed files with 57 additions and 7 deletions

View File

@ -24,12 +24,17 @@
<feature name="StatusBar"> <feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true" /> <param name="ios-package" value="CDVStatusBar" onload="true" />
</feature> </feature>
<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarBackgroundColor" value="#000000" />
<preference name="StatusBarStyle" value="lightContent" /> <!-- default, lightContent, blackTranslucent, blackOpaque -->
</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" > <config-file target="*-Info.plist" parent="UIViewControllerBasedStatusBarAppearance" >
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
</config-file> </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" />

View File

@ -32,6 +32,14 @@
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)pluginInitialize - (void)pluginInitialize
{ {
_statusBarOverlaysWebView = YES; // default _statusBarOverlaysWebView = YES; // default
@ -41,10 +49,22 @@
_statusBarBackgroundView = [[UIView alloc] initWithFrame:frame]; _statusBarBackgroundView = [[UIView alloc] initWithFrame:frame];
_statusBarBackgroundView.backgroundColor = [UIColor blackColor]; _statusBarBackgroundView.backgroundColor = [UIColor blackColor];
NSString* setting = @"StatusBarOverlaysWebView"; NSString* setting;
setting = @"StatusBarOverlaysWebView";
if ([self settingForKey:setting]) { if ([self settingForKey:setting]) {
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue]; self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
} }
setting = @"StatusBarBackgroundColor";
if ([self settingForKey:setting]) {
[self _statusBarBackgroundColorByHexString:[self settingForKey:setting]];
}
setting = @"StatusBarStyle";
if ([self settingForKey:setting]) {
[self setStatusBarStyle:[self settingForKey:setting]];
}
} }
- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView - (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView
@ -94,23 +114,43 @@
self.statusBarOverlaysWebView = [value boolValue]; self.statusBarOverlaysWebView = [value boolValue];
} }
- (void) setStatusBarStyle:(NSString*)statusBarStyle
{
// default, lightContent, blackTranslucent, blackOpaque
NSString* lcStatusBarStyle = [statusBarStyle lowercaseString];
if ([lcStatusBarStyle isEqualToString:@"default"]) {
[self styleDefault:nil];
} else if ([lcStatusBarStyle isEqualToString:@"lightcontent"]) {
[self styleLightContent:nil];
} else if ([lcStatusBarStyle isEqualToString:@"blacktranslucent"]) {
[self styleBlackTranslucent:nil];
} else if ([lcStatusBarStyle isEqualToString:@"blackopaque"]) {
[self styleBlackOpaque:nil];
}
}
- (void) styleDefault:(CDVInvokedUrlCommand*)command - (void) styleDefault:(CDVInvokedUrlCommand*)command
{ {
[self checkInfoPlistKey];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
} }
- (void) styleLightContent:(CDVInvokedUrlCommand*)command - (void) styleLightContent:(CDVInvokedUrlCommand*)command
{ {
[self checkInfoPlistKey];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
} }
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command - (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command
{ {
[self checkInfoPlistKey];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
} }
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command - (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command
{ {
[self checkInfoPlistKey];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
} }
@ -127,6 +167,16 @@
} }
} }
- (void) _statusBarBackgroundColorByHexString:(NSString*)hexString
{
unsigned int rgbValue = 0;
NSScanner* scanner = [NSScanner scannerWithString:hexString];
[scanner setScanLocation:1];
[scanner scanHexInt:&rgbValue];
_statusBarBackgroundView.backgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}
- (void) statusBarBackgroundColorByHexString:(CDVInvokedUrlCommand*)command - (void) statusBarBackgroundColorByHexString:(CDVInvokedUrlCommand*)command
{ {
NSString* value = [command.arguments objectAtIndex:0]; NSString* value = [command.arguments objectAtIndex:0];
@ -138,12 +188,7 @@
return; return;
} }
unsigned int rgbValue = 0; [self _statusBarBackgroundColorByHexString:value];
NSScanner* scanner = [NSScanner scannerWithString:value];
[scanner setScanLocation:1];
[scanner scanHexInt:&rgbValue];
_statusBarBackgroundView.backgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
} }