How to detect iPhone X (Ionic - cordova app)

For cordova

using cordova-plugin-device plugin like so:

window.device.model

will give:

iPhone10,3 or iPhone10,6

See doc:

enter image description here

For browser

see this comment


Check: var deviceInformation = ionic.Platform.device();

From Ionic bundle.js

/**
     * @ngdoc method
     * @name ionic.Platform#device
     * @description Return the current device (given by cordova).
     * @returns {object} The device object.
     */
    device: function() {
      return window.device || {};
    },

Also check cordova-plugin-device

Properties

device.cordova       // returns CDV_VERSION
 device.model
 device.platform     // always returns iOS
 device.uuid
 device.version
 device.manufacturer // always returns  Apple
 device.isVirtual    // not relevant
 device.serial 

This plugin calls CDVDevice.m -> UIDevice so if you still cannot fetch iPhone X worth to find the way how to detect it in Obj-C and change CDVDevice.m.


Also check this QA: iOS devices return different format device model, why?


I put together this es6 to check for iphone 10 and above

const isIphoneX = () => {
    try {
        const iphoneModel = window.device.model;
        const m = iphoneModel.match(/iPhone(\d+),?(\d+)?/);
        const model = +m[1];

        if (model >= 10) { // is iphone X
            return true;
        }
    } catch (e) { }

    return false;
}

** EDIT **

I believe I was using cordova-plugin-device as my project was not an ionic application. I rewrote the regex so it could work with ionic.Platform.device().model too.