我正在尝试向我的Cordova插件添加更改状态栏颜色的选项。 (我想在我的插件中执行此操作,而不要为此使用其他插件)。
我有以下代码可用于我创建的ios应用程序:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
bool isDakMode = false;
- (UIStatusBarStyle)preferredStatusBarStyle {
if (isDakMode == false) {
return UIStatusBarStyleDefault;
} else {
return UIStatusBarStyleLightContent;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)changeMe:(id)sender {
if (isDakMode == false) {
isDakMode = true;
} else {
isDakMode = false;
}
[self setNeedsStatusBarAppearanceUpdate];
}
@end
我无法在Cordova插件上使用它(无法调用preferredStatusBarStyle)。
这是我的Cordova插件代码:
#import "HWPHello.h"
@implementation HWPHello
- (void)greet:(CDVInvokedUrlCommand*)command
{
NSString* style = [[command arguments] objectAtIndex:0];
if ([style isEqualToString:@"DARK"]) {
[self setStyleForStatusBar:UIStatusBarStyleDefault];
} else {
[self setStyleForStatusBar:UIStatusBarStyleLightContent];
}
NSString* msg = [NSString stringWithFormat: @"Status bar is now in %@ color", style];
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsString:msg];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) setStyleForStatusBar:(UIStatusBarStyle)style
{
myStatusBarStyle = style;
[self refreshStatusBarAppearance];
}
- (void) refreshStatusBarAppearance
{
SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate");
if ([self.viewController respondsToSelector:sel]) {
[self.viewController performSelector:sel withObject:nil];
}
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return myStatusBarStyle;
}
@end
我想念什么? 谢谢