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

3

6

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.

Unfurl answered 8/3, 2016 at 16:42 Comment(0)
J
6

You can use this package, then just do :

console.log(DeviceInfo.getModel()); // it returns 'Simulator'
Jaymejaymee answered 8/3, 2016 at 17:13 Comment(0)
U
5

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

DeviceInfo.isEmulator()

Uranic answered 7/2, 2019 at 21:45 Comment(0)
V
1

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()).

Visitor answered 6/5, 2022 at 19:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.