How to add an icon into iphone/ipod status bar?

大憨熊 提交于 2019-12-11 03:38:53

问题


Does Apple not allow developers to add an icon into a status bar?

I followed code from a book. The code is simple:

@interface UIApplication (extended) 
- (void) addStatusBarImageNamed:(NSString *)aName; 
- (void) removeStatusBarImageNamed:(NSString *)aName; 

@end 

- (void)performAction{
    if (xxx) {
        [[UIApplication sharedApplication]addStatusBarImageNamed:@"Default_EN.png"];
    }
    else {
        [[UIApplication sharedApplication]addStatusBarImageNamed:@"Default_EC.png"];

    }
}

But it gives the following feedback :

-addStatusBarImageNamed: is deprecated. Doing nothing.

What can I do?


回答1:


In Classes/YourViewController.m, the addStatusBarImageNamed:removeOnExit: method needs to be overwritten with this.

- (void) addStatusBarImageNamed:(NSString*)image removeOnExit: (BOOL) remove {
if(_statusbarimage!=nil && _responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[self removeStatusBarImageNamed:_statusbarimage];
statusbarimage=image;
}
if (_responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[super addStatusBarImageNamed:image removeOnExit: remove];
}
}  

See if it works fine.




回答2:


To my best knowledge, this isn't permitted within the SDK, but there could be the possibilities that they could have some private API to do so but so far they haven't exposed those, I think you are'nt able to add icon in status bar. If someone know please correct me .



来源:https://stackoverflow.com/questions/6276542/how-to-add-an-icon-into-iphone-ipod-status-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!