This is a little Gem used to translate Apple iOS device types (like "iPhone6,1") to proper device names that you can use.
Add this line to your application's Gemfile:
gem 'ios-devices'And then execute:
$ bundle
Or install it yourself as:
$ gem install ios-devices
Just use the Ios::Devices.search method with the Apple string and you should get a
Ios::Devices::Model object. Its name is the product name (for example "iPad mini" or
"Apple Watch Series 5"), and its extra attribute has details like the generation or chip, size,
connectivity and variant (see Naming).
device = Ios::Devices.search('iPhone6,1')
=> #<Ios::Devices::Model:0x007fa55ba1a948 @device_type="iPhone6,1", @name="iPhone 5s", @extra=nil>
device.name
=> "iPhone 5s"
device = Ios::Devices.search('iPad2,2')
=> #<Ios::Devices::Model:0x007fa55b957308 @device_type="iPad2,2", @name="iPad 2", @extra="Wi-Fi+Cellular, GSM">
device.name
=> "iPad 2"
device.extra
=> "Wi-Fi+Cellular, GSM"
device.to_s
=> "iPad 2 (Wi-Fi+Cellular, GSM)"
device.to_h
=> {device_type: "iPad2,2", name: "iPad 2", extra: "Wi-Fi+Cellular, GSM"}
device = Ios::Devices.search('iPhone99,1')
device.name
=> "Unknown iOS device" # Ios::Devices::UNKNOWN_IOS_DEVICE
device.known?
=> falseSimulator identifiers (i386, x86_64, arm64) return "iOS Simulator".
Models are immutable, and two models with the same attributes are equal (==, eql? and
hash), so they work as hash keys and with uniq.
You can also check a device type or list every known device:
Ios::Devices.known?('iPhone6,1')
=> true
Ios::Devices.all.size
=> 239
Ios::Devices.all.select { |device| device.name == 'iPad mini' }.map(&:to_s)
=> ["iPad mini (Wi-Fi)", "iPad mini (Wi-Fi+Cellular, GSM)", ...]Names follow Apple's official product names, as on Apple's "Identify your model" support pages:
nameis Apple's name without the part in brackets: "iPad mini (6th generation)" is"iPad mini", "iPad Pro 11-inch (M4)" is"iPad Pro 11\"", and "Apple Watch Series 5" stays"Apple Watch Series 5". Numbers that are part of the name itself stay ("iPad mini 4","iPad Air 2","Apple Watch SE 3").extrais a comma-separated list of what's left, in this order (each part is optional):- generation or chip:
6th gen,M4,A17 Pro - size:
44mm - connectivity:
Wi-Fi,Wi-Fi+Cellular,GPS,GPS+Cellular - variant:
GSM,CDMA,China,Rev A,1TB
- generation or chip:
For example, iPad16,2 is "iPad mini" / "A17 Pro, Wi-Fi+Cellular" and Watch6,10 is
"Apple Watch SE" / "2nd gen, 40mm, GPS". The specs check that every entry follows these rules.
Device identifiers live in the DEVICE_TYPES hash in lib/ios/devices/device_types.rb, grouped
by family. When adding new ones:
-
Check the identifiers against at least two of these sources:
- AppleDB: identifiers per model, including upcoming devices (there are pages for iPad, Apple Watch, etc. too).
- EveryMac: identifiers broken down by regional model number (A-number).
- adamawolf's gist: a plain-text
identifier : namelist. Its comments often have new devices first, usually taken from Xcode betas, but treat those as unconfirmed.
Identifiers for unreleased devices often show up in Xcode betas before Apple ships the hardware, and they can change. Prefer adding them after the device is released.
-
Follow the naming rules. If you need a new kind of
extrapart, add it to the vocabulary inspec/ios/devices/device_types_spec.rb. -
Make sure the identifier isn't already listed. Ruby warns about duplicate keys and the specs fail on them.
-
Add a spec for at least one of the new identifiers in
spec/ios/devices_spec.rb. -
Add an entry to
CHANGELOG.mdunder the upcoming version.
Run the tests and RuboCop with bundle exec rake (or just the tests with bundle exec rake spec).
- Fork it (https://github.com/rikas/iosdevices/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request