Tom Krones Tom Krones -4 years ago 171
Objective-C Question

Hide status bar when using UIDocumentInteractionController?

I'm working on an React Native app that needs to view/share PDF files. I'm use the react-native-open-file module which uses the UIDocumentInteractionController to view PDF files. When the PDF file is opened the status bar appears over the PDF. My app has the staus bar hidden at all times. How do I hide the status bar when viewing the PDF?

Here's the code from the module:

// RNDocumentInteractionController.m
// RNDocumentInteractionController
// Created by Aaron Greenwald on 7/5/16.
// Copyright © 2016 All rights reserved.

#import "RNDocumentInteractionController.h"
#import <UIKit/UIKit.h>

@implementation RNDocumentInteractionController


UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:path];
interactionController.delegate = self;
[interactionController presentPreviewAnimated:YES];

- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
return [[[[UIApplication sharedApplication] delegate] window] rootViewController];


I was able to add a
method that hides the status after it closes but I would rather never have the status bar open at all:

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
[[UIApplication sharedApplication] setStatusBarHidden:YES];


Here's a picture of the status bar over the menu bar:

Here's a picture of the status bar over the menu bar

Answer Source

Another hacky solution:

static NSTimer* timer = nil;
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        [[UIApplication sharedApplication] setStatusBarHidden:YES];

-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
    [timer invalidate];

You can put the timer definition anywhere you want, just make sure to invalidate it once you close the preview. I have also noticed that if you put the line with setStatusBarHidden:YES inside an if clause where you check if it is actually hidden, this solution no longer works. It seems like a bug in UIDocumentInteractionController.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download