Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by jmansa · Nov 27, 2017 at 06:40 PM · iosiphone

Controlling StatusBar on iPhone X

Hi,

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 :-)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Johannski · Jan 10, 2018 at 05:31 PM

Take a look at this repo: https://github.com/HuaYe1975/UnityStatusBarForiOS

They somehow override functionality from #include "UnityViewControllerBaseiOS.h" if I got it right. Tested it with iOS 11, Unity 5.6.4p4 and Xcode9 and it works like a charm with that setup. If you use Unity 2017.2 or higher you will need to replace #include "UnityViewControllerBaseiOS.h" with #include "UnityViewControllerBase.h" in StatusBarViewController.mm.

You can easily check if the device is iPhoneX (e.g. Device.generation) and then set the status bar accordingly.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jmansa · Jan 11, 2018 at 08:28 AM 0
Share

It works like a charm. I just added it without any corrections and I am using Unity 2017+. Thanks, just saved the day ;-)

avatar image Johannski jmansa · Jan 11, 2018 at 10:14 AM 1
Share

Awesome! I was also really happy when I found the repo yesterday. I guess then the change is only needed from 2017.2 and up, changed it in the answer :)

avatar image protoshape · Sep 14, 2018 at 10:04 PM 0
Share

working great :) thanks

avatar image JohnnyFactor · Feb 15, 2019 at 08:29 PM 0
Share

This now produces many errors in Xcode 10.1, built with Unity 2018.3. $$anonymous$$ostly "Expected identifier" errors.

avatar image
0

Answer by paradizIsCool · Jan 05, 2018 at 03:14 PM

You can try to follow method 1 here https://stackoverflow.com/questions/46677240/show-status-bar-only-for-iphone-x

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image paradizIsCool · Jan 05, 2018 at 03:56 PM 0
Share

confirmed You also can checked Device.generation != DeviceGeneration.iPhoneX

if you want to show status bar only on iphone X

avatar image jmansa · Jan 06, 2018 at 10:11 AM 0
Share

@paradizlsCool The $$anonymous$$ethod described is for Swift, but appdelegate from Unity is not in Swift, so unfortunally I do not know how to implement this in Unity :-/ But thanks for the answer.

Also, in regards to detecting if its an iPhoneX inside Unity is not the issue. the issue is that I am unable to control the statusbar from within Unity when building ti iOS.

avatar image paradizIsCool · Jan 06, 2018 at 09:09 PM 0
Share

if you target ios8 you can use old method. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; https://developer.apple.com/documentation/uikit/uiapplication/1622923-setstatusbarstyle

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

158 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

linker command failed with exit code 1(use -v to see invocation) 2 Answers

Texture tilling problem on iOS 2 Answers

iOS build not rendering properly 1 Answer

Local Notification Badge Not Working On iPhoneX (iOS 11.4) 0 Answers

Failed to connect iPhone XR to unity editor 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges