iPad Pro Designation...

I use this code to make the app universal....

Anyway, does anyone know how to distinguish between all the iPad's and the iPadPro.

Or a way to list all the new device types.

Thanks for any help.




   if deviceType == "iPad" {
            F1Square.position = CGPointMake(528, 304)
            F1Square.yScale = 0.0920
        }
        if deviceType == "iPhone6Plus" {
            F1Square.position = CGPointMake(284.25, 347.25)
            F1Square.yScale = 0.0690
        }
        if deviceType == "iPhone6" {
            F1Square.position = CGPointMake(257.5, 314.5)
            F1Square.yScale = 0.0690
        }
       
        if deviceType == "iPhone5" {
            F1Square.position = CGPointMake(220, 268)
            F1Square.yScale = 0.0690
        }
        if deviceType == "iPhone" {
            F1Square.position = CGPointMake(220, 180)
            F1Square.yScale = 0.0820
        }

FYI you're setting yourself up for lots of problems doing it this way. Look into the SKScene's scaleMode property to see how to correctly handle multiple screen sizes/ratios.

This code will give you the device types.


....and yes as nilPill says, you really really don't want to be scaling things individually like that. Use the Scene scaleMode, and if you need to scale assets you can add an SKNode as a World node that you can scale as a ratio from your 'standard' size. Then attach all your game nodes as children of the world node and they will all inherit that same scale. You then don't have to worry about different device sizes.


import UIKit
private let DeviceList = [
    / iPod 5 */          "iPod5,1": "iPod Touch 5",
    / iPhone 4 */        "iPhone3,1":  "iPhone 4", "iPhone3,2": "iPhone 4", "iPhone3,3": "iPhone 4",
    / iPhone 4S */       "iPhone4,1": "iPhone 4S",
    / iPhone 5 */        "iPhone5,1": "iPhone 5", "iPhone5,2": "iPhone 5",
    / iPhone 5C */       "iPhone5,3": "iPhone 5C", "iPhone5,4": "iPhone 5C",
    / iPhone 5S */       "iPhone6,1": "iPhone 5S", "iPhone6,2": "iPhone 5S",
    / iPhone 6 */        "iPhone7,2": "iPhone 6",
    / iPhone 6 Plus */   "iPhone7,1": "iPhone 6 Plus",
    / iPad 2 */          "iPad2,1": "iPad 2", "iPad2,2": "iPad 2", "iPad2,3": "iPad 2", "iPad2,4": "iPad 2",
    / iPad 3 */          "iPad3,1": "iPad 3", "iPad3,2": "iPad 3", "iPad3,3": "iPad 3",
    / iPad 4 */          "iPad3,4": "iPad 4", "iPad3,5": "iPad 4", "iPad3,6": "iPad 4",
    / iPad Air */        "iPad4,1": "iPad Air", "iPad4,2": "iPad Air", "iPad4,3": "iPad Air",
    / iPad Air 2 */      "iPad5,1": "iPad Air 2", "iPad5,3": "iPad Air 2", "iPad5,4": "iPad Air 2",
    / iPad Mini */       "iPad2,5": "iPad Mini", "iPad2,6": "iPad Mini", "iPad2,7": "iPad Mini",
    / iPad Mini 2 */     "iPad4,4": "iPad Mini", "iPad4,5": "iPad Mini", "iPad4,6": "iPad Mini",
    / iPad Mini 3 */     "iPad4,7": "iPad Mini", "iPad4,8": "iPad Mini", "iPad4,9": "iPad Mini",
    / Simulator */       "x86_64": "Simulator", "i386": "Simulator"
]
public extension UIDevice
{
    var modelName: String
    {
        var systemInfo = utsname()
        uname(&systemInfo)
     
        let machine = systemInfo.machine
        let mirror = Mirror(reflecting: machine)
        var identifier = ""
     
        for child in mirror.children where child.value as? Int8 != 0
        {
            identifier.append(UnicodeScalar(UInt8(child.value as! Int8)))
        }
     
        return DeviceList[identifier] ?? identifier
    }
}


Then call it like so...


let myDevice = UIDevice.currentDevice().modelName

And when you look at the code four5six.pixel posted, use that as an object lesson in why you shouldn't try to use that mechanism.

Cases in point:

  • Note the absence of a case for the previous iPod touch devices
  • Note the absence of a case for the iPad Pro
  • Note how the code becomes out of date and leads to bad setting choices as new Apple devices are released
iPad Pro Designation...
 
 
Q