In a Obj-C iOS app I can use #if (TARGET_IPHONE_SIMULATOR)
to write simulator-only code.
In react native I can use:
if (__DEV__) { .. do something special }
.. to detect development mode.
We can use Platform.OS === 'ios'
to detect the platform (Android/iOS). See here for more info Platform Docs
But how do we detect if the app is running in the simulator?
The reason I ask is that my app uses the camera to scan barcodes, and this isn't supported in the iOS Simulator.
React Native device info provide isEmulator() function to check app running in emulator or not it will return only true or false . isEmulator() function work in ios, android, and windows.
You can do this pretty easily with react-native-device-info, like so:
import DeviceInfo from 'react-native-device-info' isSimulator() { // https://github.com/react-native-community/react-native-device-info#isemulator return DeviceInfo.isEmulator(); },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With