'How to know, if running on device or simulator in react native
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.
Solution 1:[1]
Since G. Hamaide's answer was posted, the DeviceInfo package has added the method isEmulator.
DeviceInfo.isEmulator()
Solution 2:[2]
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()).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rob5408 |
| Solution 2 |
