Skip to content

Instantly share code, notes, and snippets.

@inorganik
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inorganik/612f1440cb00c0c0b545 to your computer and use it in GitHub Desktop.
Save inorganik/612f1440cb00c0c0b545 to your computer and use it in GitHub Desktop.
Convert device.name to meaningfull model name
/*
With PhoneGap's device plugin, using device.name yields
something like "iPhone6,1" which is an identifier, not a
name. This function converts it to a meaningfull model name.
Example:
var model = getiOSModelName(device.name);
model = "iPhone 5s"
*/
function getiOSModelName(identifier) {
var x = identifier.search(/x/);
if (x == 0) {
return 'iOS Simulator';
} else {
var n = identifier.search(/\d/);
var model = identifier.slice(0, n);
var id = identifier.slice(n);
var models = {
iPad: {
'1,1': 'iPad 1G',
'2,1': 'iPad 2',
'2,2': 'iPad 2',
'2,3': 'iPad 2',
'2,4': 'iPad 2',
'2,5': 'iPad Mini 1G',
'2,6': 'iPad Mini 1G',
'2,7': 'iPad Mini 1G',
'3,1': 'iPad 3',
'3,2': 'iPad 3',
'3,3': 'iPad 3',
'3,4': 'iPad 4',
'3,5': 'iPad 4',
'3,6': 'iPad 4',
'4,1': 'iPad Air',
'4,2': 'iPad Air',
'4,3': 'iPad Air',
'4,4': 'iPad Mini 2G',
'4,5': 'iPad Mini 2G',
'4,6': 'iPad Mini 2G'
},
iPhone: {
'1,1': 'iPhone 2G',
'1,2': 'iPhone 3G',
'2,1': 'iPhone 3GS',
'3,1': 'iPhone 4',
'3,2': 'iPhone 4',
'3,3': 'iPhone 4',
'4,1': 'iPhone 4S',
'5,1': 'iPhone 5',
'5,2': 'iPhone 5',
'5,3': 'iPhone 5c',
'5,4': 'iPhone 5c',
'6,1': 'iPhone 5s',
'6,2': 'iPhone 5s',
'7,1': 'iPhone 6 Plus',
'7,2': 'iPhone 6'
},
iPod: {
'1,1': 'iPod touch 1G',
'2,1': 'iPod touch 2G',
'3,1': 'iPod touch 3G',
'4,1': 'iPod touch 4G',
'5,1': 'iPod touch 5G'
}
}
return models[model][id];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment