检测设备是否为 iPhone X - Detect if the device is iPhone X

问题:

My iOS app uses a custom height for the UINavigationBar which leads to some problems on the new iPhone X.我的 iOS 应用程序为UINavigationBar使用了自定义高度,这导致了新 iPhone X 上的一些问题。

Does someone already know how to reliable detect programmatically (in Objective-C) if an app is running on iPhone X?如果应用程序在 iPhone X 上运行,是否有人已经知道如何以编程方式(在 Objective-C 中)可靠地检测?

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...当然可以检查屏幕的大小,但是,我想知道是否有像TARGET_OS_IPHONE这样的“内置”方法来检测 iOS ......

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    if (screenSize.height == 812)
        NSLog(@"iPhone X");
}

EDIT 2:编辑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 (eg by some SDK feature) or do I have to use indirect measurements" ?实际问题是: “是否可以直接检测当前设备是 iPhone X(例如通过某些 SDK 功能)还是我必须使用间接测量”

By the answers given so far, I assume that the answer is "No, there is no direct methods. Measurements are the way to go".到目前为止给出的答案,我假设答案是“不,没有直接的方法。测量是要走的路”。


解决方案:

参考一: https://stackoom.com/question/37oim
参考二: Detect if the device is iPhone X
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章