Webber Lai
Webber Lai

Reputation: 2022

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

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?

Upvotes: 2

Views: 6062

Answers (2)

Nitish
Nitish

Reputation: 14123

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.

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31730

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 .

Upvotes: 2

Related Questions