檢測設備是否爲 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章