8
votes

When creating a fullscreen share extension, is there a way to control the status bar?

I tried:

  • view controller based status bar + preferredStatusBarStyle
  • status bar style
  • status bar is initially hidden

Nothing seems to affect the status bar, it is just inherited from the view that opened the share extension. Is there a workaround or is that by design how it must work?

2

2 Answers

7
votes

There's currently no way to change the status bar style for an extension view (http://openradar.appspot.com/radar?id=6397505050771456). It seems like the status bar for the extension uses the same style as the app that called the extension.

0
votes

You can actually change it if you swizzle the preferredStatusBarStyle method on the parent view controller. Since you can do that without using any non-public APIs, that * should * be app-store safe.

static UIStatusBarStyle statusBarStyle;

static UIStatusBarStyle preferredStatusBarStyle(id self, SEL _cmd)
{
  return statusBarStyle;
}

void setPreferredStatusBarStyleOnRootVC(UIStatusBarStyle style, UIViewController *vc)
{
  statusBarStyle = style;
  static BOOL swizzeld = NO;
  if(swizzeld)
  {
    [vc setNeedsStatusBarAppearanceUpdate];
    return;
  }

  swizzeld = YES;

  UIViewController *parent;
  while((parent = vc.parentViewController))
    vc = parent;

  class_addMethod(vc.class, @selector(preferredStatusBarStyle), (IMP)&preferredStatusBarStyle, "v@:");
}