A simple React Native plugin to switch a flashlight on/off.
Currently supports both iOS (>= 8.0) and Android (all versions).
Applies the permission checks on Android API >=25 devices. Below API 25, Android will automatically require the user to accept permissions on install / update.
npm install --save react-native-torchreact-native link react-native-torch
npm install react-native-torch --save
- In XCode, in the project navigator, right click
Add Files to [your project's name]
- Go to
- Expand the
- In XCode, in the project navigator, select your project. Add
libRCTTorch.ato your project's
Link Binary With Libraries
RCTTorch.xcodeprojin the project navigator and go the
Build Settingstab. Make sure 'All' is toggled on (instead of 'Basic'). In the
Search Pathssection, look for
Header Search Pathsand make sure it contains both
$(SRCROOT)/../../../React- mark both as
Without permissions check
;Torch; // Turn ONTorch; // Turn OFF
With extra permission check and dialog (Android only)
;;if PlatformOS === 'ios'Torch;elseconst cameraAllowed = await Torch;if cameraAllowedTorch;
Android catch exception accessing Torch e.g. in emulator or if device doesn't have a torch
tryawait Torch;this;catch eToastAndroid;
NOTE: iOS fails silently, on Android, you can still call without the try/catch block and it won't cause a crash
A demo application TorchDemo is also available.
Android version has flow support.