-1

I want to create if statements testing for which device the app is running on. For example, if the app is running on an iPhone 5s, change node positioning. Does anyone know how to create these statements? Thanks.

I want to test for the screen size.

EDIT:

I've found the answer. I download the SDK from here using Cocopods. Once instilled, I implemented the following code, so I could test for the size of the screen. I can then add where I want to nodes to be positioned in the if statements. It's a bit of a pain, but it's the best solution I could come up with.

let device = Device()

let iPhone4sSizedGroup: [Device] =
[.iPhone4, .iPhone4s, .Simulator(.iPhone4), .Simulator(.iPhone4s)]

if device.isOneOf(iPhone4sSizedGroup) {


}

let iPhone5sSizedGroup: [Device] =
    [.iPodTouch5, .iPodTouch6, .iPhone5, .iPhone5s, .iPhone5c, .Simulator(.iPhone5), .Simulator(.iPhone5s), .Simulator(.iPhone5c), .Simulator(.iPodTouch5), .Simulator(.iPodTouch6)]

if device.isOneOf(iPhone5sSizedGroup) {


}

let iPhone6sSizedGroup: [Device] =
[.iPhone6, .iPhone6s, .Simulator(.iPhone6), .Simulator(.iPhone6s)]

if device.isOneOf(iPhone6sSizedGroup) {


}.
Harrison R
  • 67
  • 1
  • 8
  • Check http://stackoverflow.com/a/30665494/3004003 and other answers in that question – schmidt9 Mar 29 '16 at 19:37
  • It's the same API, you can test `UIScreen.mainScreen().bounds.size.height` and `UIDevice.currentDevice().userInterfaceIdiom == .Phone` – Axel Guilmin Mar 29 '16 at 19:45
  • @AxelGuilmin ok. So could u give me an example for let's say the iPhone 5s – Harrison R Mar 29 '16 at 19:46
  • Depending on concrete model is a "NO-NO". It is determined to break in the future. Just use that what matters: screen size! – Eiko Mar 29 '16 at 21:01
  • @AxelGuilmin The scene size it is not necessarily the same size of your view – Leo Dabus Mar 29 '16 at 22:35
  • What is the real question here, do you want the device, or do you want the height? Reword the question so that people can correctly answer you. @Eiko, getting a concrete model is not determined to break in the future, an iPhone will always be an iPhone, now the problem here is iPhones have different sizes, so getting the model will not work. – Knight0fDragon Mar 29 '16 at 22:58
  • I've removed a number of comments from here; please refrain from extensive conversation in the comments section. Harrison, if the duplicate does not solve your problem please edit your question to clarify why it is not a duplicate. The edit will automatically trigger a community review to determine if your question should be reopened. Further, please do not add the answer within the question. Answers should only be in the answers section. – josliber Mar 30 '16 at 02:56

2 Answers2

3
UIDevice.currentDevice().model

is what you are looking for

Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81
  • I basically want to change to node positioning depending on the screen size. So I need to eat for the screen size. How do I do that? – Harrison R Mar 29 '16 at 19:36
  • `UIDevice.currentDevice().model` just returns 'iPhone', if you need a more precise identifier as 'iPhone 11 Pro' you should call `UIDevice.currentDevice().name`. [Here is the doc](https://developer.apple.com/documentation/uikit/uidevice/1620015-name) – Jorge Frias Nov 15 '21 at 21:23
1
let size = UIScreen.mainScreen().bounds.size
print("This is the size you are looking for \(size)");

if size.height == 568 {
    print("As an example, this is an iPhone 5/S/C/SE")
}
Yuchen
  • 30,852
  • 26
  • 164
  • 234