objective-cxcodeunity-game-engineios12

Stop app going to background when swiping up from bottom edge on iPhone X iOS 12


My game is going into background mode when performing a swipe from the bottom edge of the screen on iPhone X iOS 12.

As per Apple documentation overriding preferredScreenEdgesDeferringSystemGestures and calling setNeedsUpdateOfScreenEdgesDeferringSystemGestures should stop the app from going to background but this is's not working on iOS 12.

I am using Unity3D and the editor has the Defer system gestures on edges option , which is implemented as per apple documentation, but also does not work.

I am compiling the project in Xcode 10.

Does anyone else have this problem and do you have a fix?

PS: I am testing this in an empty single view iOS project, the only added code is the following:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear: animated];

    [self setNeedsUpdateOfHomeIndicatorAutoHidden];
    [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
}

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    return UIRectEdgeAll;
}

- (BOOL)prefersHomeIndicatorAutoHidden
{
    return YES;
}

Update: Turns out that if I use a swift implementation it works. Too bad I cannot do this for the Unity3D 2017 generated project.

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    
    if #available(iOS 11.0, *){
        setNeedsUpdateOfScreenEdgesDeferringSystemGestures()
    }
}

override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge{
    return [.all];
}
}

New Update: In Unity 2019 it works by unchecking "Status Bar Hidden" in Project Stttings\Resolution and presentation and making sure you check at least one edge in Poject Settings\Other Settings\Defer system gestures on edges


Solution

  • Removing prefersHomeIndicatorAutoHidden makes it work in Objective C also.

    This is the working example implementation, for anyone having the same problem:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        if (@available(iOS 11.0, *)) { 
          [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
        }
     }
    
    - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
    {
        return UIRectEdgeAll;
    }
    

    And for those who, like me, are using Unity3d just delete the following method from UnityViewControllerBase+iOS.mm in the generated Xcode project:

    - (BOOL)prefersHomeIndicatorAutoHidden
    {
        return YES;
    }
    

    If you're not using Unity, ensure that prefersHomeIndicatorAutoHidden is NO/false.