iPhone X - Safe Area

Hi,
Here a question for iPhone X. I would like to put the full game only in the safe area. Anyone know how can I do it?

I know that is not correct put the game only in the safe area, but in the top, I’ve the score and best score, and in the bottom, the admob banner. At the moment I don’t want to redesign the game for adapt it for iPhone X, so, my only solution is put the game only in the safe area.

Maybe exist’s some xCode configuration? or via code?
Thanks

I’m not an iOS expert, but as far as I know is compiling with Xcode 8 and iOS 10 (not the latest build tools) the way to run the app in “compat mode”, which means -> shrink into the safe area and fill the rest black.

Any other/better ideas?

Yep, I would like to fill the no safe area with black, or something like that.
I don’t know how can I change to “compat mode”. Do you know the steps for do it?

Try to compile with an older Xcode version, not the version 9.

To enable iphone x mode you need to compile project using xcode 9.x and also should have launch image for iphone x otherwise it still will run in compatibility mode.

From our last release we just re-aranged UI to not have anything in iphone x black area, alternativly u can write if for iphone x to move top elements lower when app launched on it.

But downgrade xCode to 8.x is the unique method for compile the game in the safe area only? Maybe exist’s any method for “desactivate” the unsafe-area in the game, with the last xCode… or maybe with code I can ignore unsafe-area. Is impossible?

Assuming your game is configured for full screen and not in some “backward compatible mode”.

I’d recommend for quickly adding iPhoneX support that you letterbox your game within the safe area.

Apple would rather you at least consider using the full screen such that your game displays content all the way to the edges. That will take more work and will likely require some structural changes to how you access winSize/VisibleSize/Origin/etc. It will likely require keeping the game view (or at least background) at normal full screen and adjusting UI and any touch targets such that they’re within the safe area.

Here’s some hacky code to support iPhone X (even when using Launch Storyboards or adding the new Launch image size). It’s essentially shrinking the EAGL view to “letter box” it within the safe area. Also has the small code required to defer home gesture to require a second swipe before going home or switching app.

Feel free to submit an update or otherwise comment with corrections.

@stevetranby thanks for ur help.
I’m replacing my RootViewController.mm with the code that you pasted, but the App doesn’t run. I’ve an error in main.m:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, @"AppController");
    }
}

Specifically in this line:
return UIApplicationMain(argc, argv, nil, @"AppController");

Console error:
libc++abi.dylib: terminating with uncaught exception of type NSException

What’s the error? That code will show the game (with iPhone X) only in safe area right? Sorry, i’m ignorant with Objetive-C.

The errors that are shown in main.mm are almost always just uncaught exceptions that may have occurred anywhere in your code base as it terminates and shows the stack trace, of which there is none causing it to just state that it occurred in the topmost level “main()” - you can see this is described in the error.

Debug/Testing Advice

  1. You can try to find where it was thrown by enabling an XCode ‘global’ breakpoint exception - https://stackoverflow.com/a/27037301/415
  2. Note that my code was both NOT complete, and also that I may have changed stuff from the original cocos2d template that I don’t remember off the top of my head. I’d start by adding the few functions individually and test between each. Or just comment everything out inside viewDidLoad (besides the super call) and slowly uncomment the various sections.

If you find a better error message feel free to post.
If you want to post your main, AppDelegate, and RootViewController I will take a quick look and see if I spot anything.

Commenting all viewDidLoad, i continue with the same problem.
Instead of replace all RootViewController.mm with your code, can you tell me exactly what code makes the validation if device = iPhone X -> then -> put the game only in safe area?

I don’t believe my code has a validation, however, if we assume the iOS 11 SDK behaves correctly on iPhone 8 and earlier devices then the safe area should be == the device screen bounds.

The key points are (and you’ll have to learn about them yourself if you don’t already know how they work):

  1. self.view = backgroundView; // and creating the simple bg UIView
  2. insetsLayoutMarginsFromSafeArea
  3. safeAreaInsets
  4. CCEAGLView viewWithFrame:
  5. addSubview:eaglView
  6. preferredScreenEdgesDeferringSystemGestures

If that doesn’t help you’ll have to find someone with the time to help you further diagnose and fix.