Search Unity

Option to hide iPhone X home indicator + Edge Protection

Discussion in 'iOS and tvOS' started by SweatyChair, Oct 20, 2017.

  1. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    We have adapted our game to iPhone X design and got a feedback from Apple representatives that they suggested to hide the home indicator in game and enable "Edge Protection" (swipe up once to show home indicator, swipe up again to go back home as said here)

    I believe it's not there yet in Unity? It will be great if Unity can add this in (just an option below "Status Bar Hidden").

    There's a post on how to do this with iOS native code. I don't really understand so better wait for Unity...

    Here is the feature request I made, vote it up if this matters you.

    Screen Shot 2017-10-20 at 5.35.17 pm.png
     
    Last edited: Oct 20, 2017
  2. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hi. This feature is in development and will be released in near future.
     
    jGate99 likes this.
  3. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    Very nice, please do update here if that's implemented in any new version/patch.
     
    RocketBoyStudioGames likes this.
  4. h0lmie

    h0lmie

    Joined:
    Oct 13, 2015
    Posts:
    5
    You can do it yourself for now if you use Xcode 9.

    Add

    - (BOOL)prefersHomeIndicatorAutoHidden
    {
        return YES;
    }

    To UnityViewControllerBaseiOS.mm
     
    ADNCG, DanarKayfi and hgbimonti like this.
  5. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    This is for both status and edge protection

    UnityViewControllerBaseiOS.h
    Code (CSharp):
    1.  
    2. @interface UnityViewControllerBase : UIViewController
    3. {
    4. }
    5.  
    6. - (BOOL)shouldAutorotate;
    7.  
    8. - (BOOL)prefersStatusBarHidden;
    9. - (UIStatusBarStyle)preferredStatusBarStyle;
    10. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures; // add this
    11. - (BOOL)prefersHomeIndicatorAutoHidden; // add this
    12. @end
    13.  
    UnityViewControllerBaseiOS.mm
    Code (CSharp):
    1.  
    2. - (BOOL)shouldAutorotate
    3. {
    4.     return YES;
    5. }
    6.  
    7. // add this
    8. - (BOOL)prefersHomeIndicatorAutoHidden
    9. {
    10.     return YES;
    11. }
    12.  
    13. // add this
    14. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
    15. {
    16.     return UIRectEdgeAll;
    17. }
    18.  
    19. - (BOOL)prefersStatusBarHidden
    20. {
    21. ....
    22.  
     
    protopop, ADNCG, igor_rst and 3 others like this.
  6. sergioabril

    sergioabril

    Joined:
    Jan 11, 2016
    Posts:
    33

    Hi guys,

    Whenever I add this, my home indicator disappears, yes, but as soon as I tap the screen (anywhere, and not even doing a swipe), home indicator appears again. Is this the expected behavior? It makes Home Indicator even more annoying, since my game is a point and click, and you are tapping the screen all the time. I hope I'm missing something :/
     
  7. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    I'm using the option for hiding it that unity added on the last patch (Unity 2017.2.0p2) and same thing happens, so I guess it's the expected behaviour.

    I don't see the point on hiding it on any app or games, it's just distracting. I only see it useful if you are watching a video or something like that.
     
    User340 likes this.
  8. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I agree that it's primary intention is most likely watching videos. Let's hope that they make it optionally hide completely so that we can take full advantage of the real estate.
     
  9. acproctor

    acproctor

    Joined:
    Oct 28, 2015
    Posts:
    3
    I'm going to give this a test, but if the behaviour is as you've described then I don't think it's the only way to enable edge protection. I was playing Campfire Cooking on an iPhone X and it had edge protection turned on. In that game the home indicator stays low opacity until you actually swipe up on (or near) the home indicator, and doesn't activate on every screen tap.
     
  10. acproctor

    acproctor

    Joined:
    Oct 28, 2015
    Posts:
    3
    Ok, i just ran some builds on 2017.2.0p2 I think the behaviour most people want is just putting on bottom edge protection, and not enabling auto-hide. Auto hide of the bottom bar in unity settings will (as you described) hide the bar completely, but show it full brightness on any screen tap. But if you just set the deferred gesture protection on the bottom bar, it will fade out the bar mostly and will only enable when you swipe near the bar (requiring a double swipe to dismiss your app).

    This is the way Campfire Cooking was behaving, and I think the iOS recommended way. Auto-hiding basically was only recommended for video-player like applications. In fact they don't really recommend doing either option, but I think if your game has issues conflicting with the gesture they're ok with it.
     

    Attached Files:

    User340 likes this.
  11. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    @acproctor
    Thanks, we don't have an iPhoneX to test yet and your answer seems solid and we will just fellow~
     
    Last edited: Nov 24, 2017
  12. xianhui1

    xianhui1

    Joined:
    Jan 12, 2017
    Posts:
    1
    Hey, I find your request, you can try to add the following code in the
    UnityViewControllerBase class, and then there are no changes in other places.
    - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures

    {

    return UIRectEdgeAll;

    }
     
  13. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    FYI, I do see a "Hide Home Button on IPhoneX" in Unity 2017.3 f2
     
  14. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    59
    Hey guys, I want to completely remove the home bar in iPhone X. jeffweber "Hide Home Button on IPhoneX" option hides it but it is visible immediately after we touch the screen. It's not practical for games. I don't want to see the home bar at all unless I swipe up from bottom. Is it possible?? Any Unity officials to reply??
     
  15. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    @dhanrajsinh24: Unfortunately the actual visibility is controlled by iOS. We can't force it to hide home button at all times as far as I know.
     
  16. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    59
    Last edited: Jul 18, 2018
  17. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    No it doesn’t. They’re just deferring swipe gestures from the bottom, which can absolutely be done from within Unity.
     
  18. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    59
    @_Daniel_ Are you sure? I've tried to use defer option from Player Settings and it did not work in iPhone X Xcode simulator.
     
  19. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Did you have Auto Hide Home Indicator disabled? It must be disabled in order for deferring to work.
     
  20. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    59
    @_Daniel_ No I did not do that. Thank you for your help. I will try that now.
     
  21. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    Does anyone know how i find and edit these files?

    Do i do it in xcode after Unity has created the xcode project?
     
  22. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    I found them. For other non coders like me, They are inside the build folder Unity creates for your ios project. I did a spotlight search to find them. Double clicking them opens them up in xcode, although i haven't figured out how to save edits to them yet. Also the .h file opens in a seperate window, but you can still edit it in there.
     
  23. BigRedGames

    BigRedGames

    Joined:
    Jun 25, 2016
    Posts:
    48
    Hi dhanrajsinh24 did you find if using the "Deferring" option and disabling the "Hide home button" worked? I tested this setup on the Simulator, but it didn't work as well.
     
  24. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Why doesn't Unity have this option enabled?

    The above solution worked great but the classes file name changed:
    UnityViewControllerBase+iOS.mm
    UnityViewControllerBase+iOS.h
    Code (CSharp):
    1. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
    2. {
    3.     UIRectEdge res = UIRectEdgeNone;
    4.     if (UnityGetDeferSystemGesturesTopEdge())
    5.         res |= UIRectEdgeTop;
    6.     if (UnityGetDeferSystemGesturesBottomEdge())
    7.         res |= UIRectEdgeBottom;
    8.     if (UnityGetDeferSystemGesturesLeftEdge())
    9.         res |= UIRectEdgeLeft;
    10.     if (UnityGetDeferSystemGesturesRightEdge())
    11.         res |= UIRectEdgeRight;
    12. //    return res;
    13.     return UIRectEdgeAll;
    14. }
    Code (CSharp):
    1. - (BOOL)prefersStatusBarHidden
    2. {
    3.     static bool _PrefersStatusBarHidden = true;
    4.  
    5.     static bool _PrefersStatusBarHiddenInited = false;
    6.     if (!_PrefersStatusBarHiddenInited)
    7.     {
    8.         NSNumber* hidden = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"UIStatusBarHidden"];
    9.         _PrefersStatusBarHidden = hidden ? [hidden boolValue] : YES;
    10.  
    11.         _PrefersStatusBarHiddenInited = true;
    12.     }
    13. //    return _PrefersStatusBarHidden;
    14.     return YES;
    15. }
     
    Rachan likes this.
  25. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    782
    I really want to know how to custom Indicator home. I know that it cannot hide.. it's ok for me
    But, it too bright why it cannot custom it or just changing a color?
    it would be better, it so white and bright!
     
  26. vistawaplord

    vistawaplord

    Joined:
    Jul 9, 2021
    Posts:
    1