Created
March 21, 2018 18:01
-
-
Save NathanWalker/ae01b826e4122f16d4aa3f08b53bd772 to your computer and use it in GitHub Desktop.
NativeScript utility: isIPhoneX detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isIOS } from 'tns-core-modules/platform'; | |
let iPhoneX; | |
export function isIPhoneX() { | |
if (isIOS) { | |
if (typeof iPhoneX === 'undefined') { | |
const _SYS_NAMELEN: number = 256; | |
const buffer: any = interop.alloc(5 * _SYS_NAMELEN); | |
uname(buffer); | |
let name: string = NSString.stringWithUTF8String( | |
buffer.add(_SYS_NAMELEN * 4) | |
).toString(); | |
// Get machine name for Simulator | |
if (name === 'x86_64' || name === 'i386') { | |
name = NSProcessInfo.processInfo.environment.objectForKey( | |
'SIMULATOR_MODEL_IDENTIFIER' | |
); | |
} | |
// console.log('isIPhoneX name:', name); | |
iPhoneX = name.indexOf('iPhone10,3') === 0 || name.indexOf('iPhone10,6') === 0; | |
} | |
return iPhoneX; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment