A simple method to obtain the detailed model of your device

Apple’s product line is diverse, and here we have collected some of them in a table to help you identify the specific model of your device.

-- Use this function to perform your initial setup
function setup()

    local mydm = deviceMetrics()
    
    for k,v in pairs(mydm) do
        print(k,v)
    end
    
    print("This device is: ", deviceInfo[mydm.platform].typename)
    
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)    
end

--iPhone
deviceInfo = {
    ["iPhone3,1"] = { platform="iPhone3,1", typename = "iPhone 4"}, 
    ["iPhone3,2"] = { platform="iPhone3,2", typename = "Verizon iPhone 4"}, 
    ["iPhone3,3"] = { platform="iPhone3,3", typename = "iPhone 4"}, 
    ["iPhone4,1"] = { platform="iPhone4,1", typename = "iPhone 4S"}, 
    ["iPhone5,1"] = { platform="iPhone5,1", typename = "iPhone 5"}, 
    ["iPhone5,2"] = { platform="iPhone5,2", typename = "iPhone 5 (GSM+CDMA)"}, 
    ["iPhone5,3"] = { platform="iPhone5,3", typename = "iPhone 5c (GSM)"}, 
    ["iPhone5,4"] = { platform="iPhone5,4", typename = "iPhone 5c (GSM+CDMA)"}, 
    ["iPhone6,1"] = { platform="iPhone6,1", typename = "iPhone 5s (GSM)"}, 
    ["iPhone6,2"] = { platform="iPhone6,2", typename = "iPhone 5s (GSM+CDMA)"}, 
    ["iPhone7,1"] = { platform="iPhone7,1", typename = "iPhone 6 Plus"}, 
    ["iPhone7,2"] = { platform="iPhone7,2", typename = "iPhone 6"}, 
    ["iPhone8,1"] = { platform="iPhone8,1", typename = "iPhone 6s"}, 
    ["iPhone8,2"] = { platform="iPhone8,2", typename = "iPhone 6s Plus"}, 
    ["iPhone8,4"] = { platform="iPhone8,4", typename = "iPhone SE"}, 
    ["iPhone9,1"] = { platform="iPhone9,1", typename = "iPhone 7"},  --国行、日版、港行
    ["iPhone9,2"] = { platform="iPhone9,2", typename = "iPhone 7 Plus"},  --国行、港行
    ["iPhone9,3"] = { platform="iPhone9,3", typename = "iPhone 7"},  --美版、台版
    ["iPhone9,4"] = { platform="iPhone9,4", typename = "iPhone 7 Plus"},  --美版、台版
    ["iPhone10,1"] = { platform="iPhone10,1", typename = "iPhone 8"},  --国行(A1863)、日行(A1906)
    ["iPhone10,2"] = { platform="iPhone10,2", typename = "iPhone 8 Plus"},  --国行(A1864)、日行(A1898)
    ["iPhone10,3"] = { platform="iPhone10,3", typename = "iPhone X"},  --国行(A1865)、日行(A1902)
    ["iPhone10,4"] = { platform="iPhone10,4", typename = "iPhone 8"},  --美版(Global/A1905)
    ["iPhone10,5"] = { platform="iPhone10,5", typename = "iPhone 8 Plus"},  --美版(Global/A1897)
    ["iPhone10,6"] = { platform="iPhone10,6", typename = "iPhone X"}, --美版(Global/A1901)
    ["iPhone10,8"] = { platform="iPhone11,8", typename = "iPhone XR"}, 
    ["iPhone11,2"] = { platform="iPhone11,2", typename = "iPhone XS"}, 
    ["iPhone11,6"] = { platform="iPhone11,6", typename = "iPhone XS Max"}, 
    ["iPhone11,4"] = { platform="iPhone11,4", typename = "iPhone XS Max"}, 
    ["iPhone12,1"] = { platform="iPhone12,1", typename = "iPhone 11"}, 
    ["iPhone12,3"] = { platform="iPhone12,3", typename = "iPhone 11 Pro"}, 
    ["iPhone12,5"] = { platform="iPhone12,5", typename = "iPhone 11 Pro Max"}, 
    ["iPhone12,8"] = { platform="iPhone12,8", typename = "iPhone SE"},  --(2nd generation)
    ["iPhone13,1"] = { platform="iPhone13,1", typename = "iPhone 12 mini"}, 
    ["iPhone13,2"] = { platform="iPhone13,2", typename = "iPhone 12"}, 
    ["iPhone13,3"] = { platform="iPhone13,3", typename = "iPhone 12 Pro"}, 
    ["iPhone13,4"] = { platform="iPhone13,4", typename = "iPhone 12 Pro Max"}, 
    ["iPhone14,2"] = { platform="iPhone14,2", typename = "iPhone 13 Pro"}, 
    ["iPhone14,3"] = { platform="iPhone14,3", typename = "iPhone 13 Pro Max"}, 
    ["iPhone14,4"] = { platform="iPhone14,4", typename = "iPhone 13 mini"}, 
    ["iPhone14,5"] = { platform="iPhone14,5", typename = "iPhone 13"}, 
    ["iPhone14,6"] = { platform="iPhone14,6", typename = "iPhone SE"},  --(2nd generation)
    ["iPhone14,7"] = { platform="iPhone14,7", typename = "iPhone 14"}, 
    ["iPhone14,8"] = { platform="iPhone14,8", typename = "iPhone 14 Plus"}, 
    ["iPhone15,2"] = { platform="iPhone15,2", typename = "iPhone 14 Pro"}, 
    ["iPhone15,3"] = { platform="iPhone15,3", typename = "iPhone 14 Pro Max"}, 
    
    --iPad
    ["iPad1,1"] = { platform="iPad1,1", typename = "iPad"}, 
    ["iPad1,2"] = { platform="iPad1,2", typename = "iPad 3G"}, 
    
    ["iPad2,1"] = { platform="iPad2,1", typename = "iPad 2 (WiFi)"}, 
    ["iPad2,2"] = { platform="iPad2,2", typename = "iPad 2"}, 
    ["iPad2,3"] = { platform="iPad2,3", typename = "iPad 2 (CDMA)"}, 
    ["iPad2,4"] = { platform="iPad2,4", typename = "iPad 2"}, 
    ["iPad2,5"] = { platform="iPad2,5", typename = "iPad Mini (WiFi)"}, 
    ["iPad2,6"] = { platform="iPad2,6", typename = "iPad Mini"}, 
    ["iPad2,7"] = { platform="iPad2,7", typename = "iPad Mini (GSM+CDMA)"}, 
    
    ["iPad3,1"] = { platform="iPad3,1", typename = "iPad 3 (WiFi)"}, 
    ["iPad3,2"] = { platform="iPad3,2", typename = "iPad 3 (GSM+CDMA)"}, 
    ["iPad3,3"] = { platform="iPad3,3", typename = "iPad 3"}, 
    ["iPad3,4"] = { platform="iPad3,4", typename = "iPad 4 (WiFi)"}, 
    ["iPad3,5"] = { platform="iPad3,5", typename = "iPad 4"}, 
    ["iPad3,6"] = { platform="iPad3,6", typename = "iPad 4 (GSM+CDMA)"}, 
    
    ["iPad4,1"] = { platform="iPad4,1", typename = "iPad Air (WiFi)"}, 
    ["iPad4,2"] = { platform="iPad4,2", typename = "iPad Air (Cellular)"}, 
    ["iPad4,3"] = { platform="iPad4,3", typename = "iPad Air"}, 
    
    ["iPad4,4"] = { platform="iPad4,4", typename = "iPad Mini 2 (WiFi)"}, 
    ["iPad4,5"] = { platform="iPad4,5", typename = "iPad Mini 2 (Cellular)"}, 
    ["iPad4,6"] = { platform="iPad4,6", typename = "iPad Mini 2"}, 
    
    ["iPad4,7"] = { platform="iPad4,7", typename = "iPad Mini 3"}, 
    ["iPad4,8"] = { platform="iPad4,8", typename = "iPad Mini 3"}, 
    ["iPad4,9"] = { platform="iPad4,9", typename = "iPad Mini 3"}, 
    
    ["iPad5,1"] = { platform="iPad5,1", typename = "iPad Mini 4 (WiFi)"}, 
    ["iPad5,2"] = { platform="iPad5,2", typename = "iPad Mini 4 (LTE)"}, 
    ["iPad5,3"] = { platform="iPad5,3", typename = "iPad Air 2"}, 
    ["iPad5,4"] = { platform="iPad5,4", typename = "iPad Air 2"}, 
    
    ["iPad6,3"] = { platform="iPad6,3", typename = "iPad Pro 9.7"}, 
    ["iPad6,4"] = { platform="iPad6,4", typename = "iPad Pro 9.7"}, 
    ["iPad6,7"] = { platform="iPad6,7", typename = "iPad Pro 12.9"}, 
    ["iPad6,8"] = { platform="iPad6,8", typename = "iPad Pro 12.9"}, 

    ["iPad6,11"] = { platform="iPad6,11", typename = "iPad 5th"}, 
    ["iPad6,12"] = { platform="iPad6,12", typename = "iPad 5th"}, 
    
    ["iPad7,1"] = { platform="iPad7,1", typename = "iPad Pro 12.9 2nd"}, 
    ["iPad7,2"] = { platform="iPad7,2", typename = "iPad Pro 12.9 2nd"}, 
    ["iPad7,3"] = { platform="iPad7,3", typename = "iPad Pro 10.5"}, 
    ["iPad7,4"] = { platform="iPad7,4", typename = "iPad Pro 10.5"}, 
    
    ["iPad7,5"] = { platform="iPad7,5", typename = "iPad 6th"}, 
    ["iPad7,6"] = { platform="iPad7,6", typename = "iPad 6th"}, 
    
    ["iPad8,1"] = { platform="iPad8,1", typename = "iPad Pro 11"}, 
    ["iPad8,2"] = { platform="iPad8,2", typename = "iPad Pro 11"}, 
    ["iPad8,3"] = { platform="iPad8,3", typename = "iPad Pro 11"}, 
    ["iPad8,4"] = { platform="iPad8,4", typename = "iPad Pro 11"}, 
    
    ["iPad8,5"] = { platform="iPad8,5", typename = "iPad Pro 12.9 3rd"}, 
    ["iPad8,6"] = { platform="iPad8,6", typename = "iPad Pro 12.9 3rd"}, 
    ["iPad8,7"] = { platform="iPad8,7", typename = "iPad Pro 12.9 3rd"}, 
    ["iPad8,8"] = { platform="iPad8,8", typename = "iPad Pro 12.9 3rd"}, 
    
    ["iPad11,1"] = { platform="iPad11,1", typename = "iPad mini 5th"}, 
    ["iPad11,2"] = { platform="iPad11,2", typename = "iPad mini 5th"}, 
    ["iPad11,3"] = { platform="iPad11,3", typename = "iPad Air 3rd"}, 
    ["iPad11,4"] = { platform="iPad11,4", typename = "iPad Air 3rd"}, 
    
    ["iPad11,6"] = { platform="iPad11,6", typename = "iPad 8th"}, 
    ["iPad11,7"] = { platform="iPad11,7", typename = "iPad 8th"}, 
    
    ["iPad12,1"] = { platform="iPad12,1", typename = "iPad 9th"}, 
    ["iPad12,2"] = { platform="iPad12,2", typename = "iPad 9th"}, 
    
    ["iPad14,1"] = { platform="iPad14,1", typename = "iPad mini 6th"}, 
    ["iPad14,2"] = { platform="iPad14,2", typename = "iPad mini 6th"}, 
    
    --iPod
    ["iPad1,1"] = { platform="iPod1,1", typename = "iPod Touch 1G"}, 
    ["iPad2,1"] = { platform="iPod2,1", typename = "iPod Touch 2G"}, 
    ["iPad3,1"] = { platform="iPod3,1", typename = "iPod Touch 3G"}, 
    ["iPad4,1"] = { platform="iPod4,1", typename = "iPod Touch 4G"}, 
    ["iPad5,1"] = { platform="iPod5,1", typename = "iPod Touch (5 Gen)"}, 
    ["iPad7,1"] = { platform="iPod7,1", typename = "iPod Touch (6 Gen)"}, 
    ["iPad9,1"] = { platform="iPod9,1", typename = "iPod Touch (7 Gen)"}, 

    ["i386"] = { platform="i386", typename = "Simulator"}, 
    ["x86_64"] = { platform="x86_64", typename = "Simulator"}, 
}

Run it you will get below:

batteryState	unplugged

platformName	Unknown iPad

platform	iPad8,5

batteryLevel	0.69999998807907

systemName	iPadOS

systemVersion	17.3.1

name	iPad

hwmodel	J320AP

This device is: 	iPad Pro 12.9 3rd

Here is the product information link.

@binaryblues - thanks for the project, I started building up my own data list a while ago, largely because I wanted to know the different resolutions available so I could check out my code at different resolutions. Unfortunately- your code fires up an error.:

Documents/AppleDevData/Main.lua:13: attempt to index a nil value (field '?')
stack traceback:
	Documents/AppleDevData/Main.lua:13: in function 'setup'

P.s. curious - what’s the PC simulator listed and thanks for the link.

@Bri_G Thank you for the response, I run it on 3.x, if select 4.x, it will return error:

Error in call to setup():
Documents/TestCodeCraft/Main.lua:4: attempt to call a nil value (global 'deviceMetrics')
stack traceback:
	Documents/TestCodeCraft/Main.lua:4: in function 'base.setup'

However, it does not seem to be the issue you’ve encountered. Line 13 appears to be an empty line after an ‘end’. Let me check what’s going on.

Regarding the last two simulators, I am not certain what they correspond to; perhaps they are utilized within Xcode.

@Bri_G Please try this one:

GetDevice.zip (2.1 KB)

@binaryblues - sorry still bombs out on me, error below.

I’m on 3.10.1 (456)


Documents/GetDevice/Main.lua:10: attempt to index a nil value (field '?')
stack traceback:
	Documents/GetDevice/Main.lua:10: in function 'setup'

@Bri_G Please try this one, I changed the order of the code, placing deviceInfo at the forefront.
GetDevice.zip (2.1 KB)

@binaryblues - good idea but it failed again. Think this must be due to running it in the latest beta. The error from this version was as follows:


Documents/GetDevice%201/Main.lua:150: attempt to index a nil value (field '?')
stack traceback:
	Documents/GetDevice%201/Main.lua:150: in function 'setup'

Could it be something to do with the call you have made ? Seems a bit odd if it works on yours I’m going to try it on my other app which is not on the latest beta.

@binaryblues - think I may have found the problem, I added a print(#mydm) after you have defined it and it returns 0. So the table has no data present hence the code can not read it.

@sim - do you know of any reason behind this issue with the latest beta?

@Bri_G Indeed, it’s quite peculiar. I just thought of a possibility that the iPad model you’re using might not be included in the table I provided earlier. Please check it out.

Add a line of code before the statement that’s causing the error to see what string your device returns. This database seems to be from the year 2023, and if you are using the latest Apple device, it’s likely not recorded in the table.

    print("My device: ", mydm.platform)
    print("This device is: ", deviceInfo[mydm.platform].typename)

@Bri_G It does seem quite strange. To my understanding, this function deviceMetrics() was deprecated in version 4.x, but it appears that you are using version 3.x.

@binaryblues - added the line as requested and it came back with

My device: iPad14,3

Another thought just occurred to me, I have installed the latest iOS update on this pad today, that is 17.4.1. Could the OS be causing any issues ?

Edit: just rechecked your tabulated data and the iPad 14, 3 is not on the list.

@Bri_G I believe we’ve found the reason; your device is not listed in the table. The iOS version should not affect this, but it seems an update to the table is necessary. Manually add an entry, and you should be able to see the output.

@binaryblues - after adding a line to the table your project ran fine on both my old and new iPads.

I’m not sure if the table is correct as it looks like lates pad was described as a mini. Is there another source for the data in the tables ?

@Bri_G Besides this link https://github.com/zou-xian/DevicePlatForm, it also includes ‘Watch’, and I haven’t found a better source for now. It might require us to improve this product model list by ourselves. Fortunately, Apple only releases a few new products each year.