My iOS app uses a custom height for the UINavigationBar
which leads to some problems on the new iPhone X.
Does someone already know how to reliable detect programmatically (in Objective-C) if an app is running on iPhone X?
EDIT:
Of course checking the size of the screen is possible, however, I wonder if there is some "build in" method like TARGET_OS_IPHONE
to detect iOS…
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.height == 812)
NSLog(@"iPhone X");
}
EDIT 2:
I do not think, that my question is a duplicate of the linked question. Of course, there are methods to "measure" different properties of the current device and to use the results to decide which device is used. However, this was not the actual point of my question as I tried to emphasize in my first edit.
The actual question is: "Is it possible to directly detect if the current device is an iPhone X (e.g. by some SDK feature) or do I have to use indirect measurements"?
By the answers given so far, I assume that the answer is "No, there is no direct methods. Measurements are the way to go".
Best Answer
Based on your question, the answer is no. There are no direct methods. For more information you can get the information here:
and
The iPhone X height is 2436 px
From Device Screen Sizes and resolutions:
From Device Screen Sizes and Orientations:
Swift 3 and later:
Objective-C:
Xamarin.iOS:
Based on your question as follow:
Or use
screenSize.height
as float812.0f
not int812
.For more information you can refer the following page in iOS Human Interface Guidelines:
Swift:
Detect with
topNotch
:Objective-C:
UPDATE:
Do not use the
userInterfaceIdiom
property to identify the device type, as the documentation for userInterfaceIdiom explains:That is, this property is just used to identify the running app's view style. However, the iPhone app (not the universal) could be installed in iPad device via App store, in that case, the
userInterfaceIdiom
will return theUIUserInterfaceIdiomPhone
, too.The right way is to get the machine name via
uname
. Check the following for details: