Unity Controlling StatusBar on iPhone X

Viewed 1010

I have a game, in which all earlier versions of iPhone (3 - 8) is build without the Statusbar, but now with the iPhone X, after altering my UI to fit the iPhone X screen has 2 blank spots in the top.

Instead of leaving them blank, it would be nice to activate the statusbar to fill them out.

This means that I have to do this by script and in runtime.

I have looked at the UnityPlayer.PlayerSettings.statusBarHidden function, but this will not work :-/

I found this post, but am not able to make it work: https://answers.unity.com/questions/688922/hideshow-status-bar-androidios-on-runtime.html

Here is what I have tried:

Added this to plugins -> ios in my unity project:

StatusBar.mm

 #import "StatusBar.h"

 @implementation StatusBar
 + (void) hideStatusBar: (BOOL)hide
 {
     [[UIApplication sharedApplication] setStatusBarHidden: hide
                                             withAnimation: UIStatusBarAnimationSlide];
     [UnityGetGLViewController() setNeedsStatusBarAppearanceUpdate];
 }
 @end

 extern "C"
 {
     void StatusBarSwitcherPressed(bool isHide)
     {
         [StatusBar hideStatusBar: isHide];
     }
 }

StatusBar.h

#import <Foundation/Foundation.h>

 @interface StatusBar : NSObject
 {
     // Keeps track of available services
     NSMutableArray *services;

     // Keeps track of search status
     NSString* status;
     BOOL searching;
 }
 @end

I then added this c# file inside the plugin folder:

 using UnityEngine;
 using System.Collections;
 using System.Runtime.InteropServices;

 public class StatusBarCtrl {

     [DllImport ("__Internal")]
     private static extern void StatusBarSwitcherPressed (bool isHide);

     public static void StausBarHide(bool isHide)
     {
         // Call plugin only when running on real device
         if (Application.platform != RuntimePlatform.OSXEditor)
             StatusBarSwitcherPressed(isHide);
     }

 }

And then calls this when I have figured out if its an iPhone X or not:

StatusBarCtrl.StausBarHide (false);

Hope this makes sense. When running this, nothing happens whether I set it to true or false :-/

Any help is appreciated and thanks in advance :-)

0 Answers
Related