PHP 51Degrees solution can do this. you can get a free open source API here https://github.com/51Degrees/Device-Detection . You can use the HardwareFamily property to determine if it is an iPad / iPod / iPhone, etc.
Due to the nature of Apple user agents, the original result will return a universal device, however, if you are interested in a specific device, you can use the JavaScript JavaScript client override to define a specific model.
To do this, you can implement something similar to the following logic, as soon as you determine that this is an Apple device, in this case for the iPhone.
// iPhone model checks. function getiPhoneModel() { // iPhone 6 Plus if ((window.screen.height / window.screen.width == 736 / 414) && (window.devicePixelRatio == 3)) { return "iPhone 6 Plus"; } // iPhone 6 else if ((window.screen.height / window.screen.width == 667 / 375) && (window.devicePixelRatio == 2)) { return "iPhone 6"; } // iPhone 5/5C/5S or 6 in zoom mode else if ((window.screen.height / window.screen.width == 1.775) && (window.devicePixelRatio == 2)) { return "iPhone 5, 5C, 5S or 6 (display zoom)"; } // iPhone 4/4S else if ((window.screen.height / window.screen.width == 1.5) && (window.devicePixelRatio == 2)) { return "iPhone 4 or 4S"; } // iPhone 1/3G/3GS else if ((window.screen.height / window.screen.width == 1.5) && (window.devicePixelRatio == 1)) { return "iPhone 1, 3G or 3GS"; } else { return "Not an iPhone"; }; }
Or for iPad
function getiPadVersion() { var pixelRatio = getPixelRatio(); var return_string = "Not an iPad"; if (pixelRatio == 1 ) { return_string = "iPad 1, iPad 2, iPad Mini 1"; } if (pixelRatio == 2) { return_string = "iPad 3, iPad 4, iPad Air 1, iPad Air 2, iPad Mini 2, iPad Mini 3"; } return return_string; }
For more information about research done on Apple devices, you can read their blog post here https://51degrees.com/blog/device-detection-for-apple-iphone-and-ipad .
Disclosure: I work for 51Degrees.
Zarwalski Apr 12 '17 at 9:48 on 2017-04-12 09:48
source share