How to know, if running on device or simulator in react native

Viewed 3027

To distinguish between development mode and production mode in react native there is the __DEV__ constant defined, when Debug = True.

Is there a similar constant defined, that lets me know within the code, if the code is running on the device or in the simulator?

Where else could I get this kind of information from.

3 Answers

Since G. Hamaide's answer was posted, the DeviceInfo package has added the method isEmulator.

DeviceInfo.isEmulator()

there's a caveat here, DeviceInfo.isEmulator() returns a promise, so if you use if(DeviceInfo.isEmulator()), it'll return true even if running on a real device. Use DeviceInfo.isEmulatorSync() or if(await DeviceInfo.isEmulator()).

Related