LibStatusBar icon disappears on 3rd-party app launch

I wrote a tweak for Cydia, it adds an icon to the status bar. It works fine on the home screen and when SpringBoard is launched, also, if an app is already launched then it works fine, however, if an app (such as Facebook or Twitter) is closed (completely) and the icon is showing, when launching the app, it will cause the icon to disappear. The icon is displayed using libStatusBar using this code:

if(icon) // if icon needs to be removed
{
    [icon release];
    icon = nil;
}

...

// add the icon to the status bar
icon = [[%c(LSStatusBarItem) alloc] initWithIdentifier:[NSString stringWithFormat:@"muteIconLablabla"] alignment:StatusBarAlignmentRight];
icon.imageName = [NSString stringWithFormat:@"Mute"];

I also tried using the methods suggested in libStatusBar README file

[[UIApplication sharedApplication] addStatusBarImageNamed:@"ON_Mute"]; // and removeStatusBarImageNamed:...

I tried overriding -(id)init and updating the icon there, but the same result.

The code shown above is being called from a static void function. this function is being called several times, for example from -(void)applicationDidFinishLaunching:(id)application under %hook SpringBoard and -(void)ringerChanged:(int)changed

All inside Tweak.xm. The problem happens in iOS7 as well.


Solution 1:

It's been a while since I've used libstatusbar, but if you are absolutely sure the LSStatusBarItem is not being released, it's possible it's being hidden by Springboard or another app. Consider setting icon.visible = YES explicitly. You also might want to consider setting timeHidden on LSStatusBarServer to NO explicitly by calling [item setHidesTime:NO].

Additionally, if you're not making any changes to the icon, set icon.manualUpdate = NO.

References:

  • Libstatusbar on the iPhoneDevWiki
  • LSStatusBarItem.mm source