Ionic native flash light plugin not working with cordova-camera-preview?

Here is my code…

   startCamera(){
     const cameraPreviewOpts: CameraPreviewOptions = {
       x: 30,
       y: 80,
       width: this.calcWidth,
       height: this.calcHeight,
       camera: 'rear',
       tapPhoto: false,
       previewDrag: false,
       toBack: false,
       alpha: 1
     };
     // start camera
     this.cameraPreview.startCamera(cameraPreviewOpts).then(
     	(res) => {
     		console.log(res)

     	},
     	(err) => {
     		console.log(err)
     	});    
     
     this.cameraPreview.setFlashMode("on").
     then(data=>{
       console.log(data);
     }).catch(err=>{
       console.log(err);
     });
     
   }

   takePhoto(){
     console.log("Take Photo");
     // let size = {maxWidth: 1024, maxHeight: 640};
     // CameraPreview.takePicture(size);         //Decrepted// picture options
     const pictureOpts: CameraPreviewPictureOptions = {
       quality: 85
     }
     // take a picture
     this.cameraPreview.takePicture(pictureOpts).then((imageData) => {
       // imageData is a base64 encoded string
       this.base64Image = "data:image/jpeg;base64," + imageData;
       this.rewardsCommonData.currentlyCapturedImage=this.base64Image;
       // Stop the camera preview
       this.cameraPreview.stopCamera();
       this.app.getRootNav().push(ConfirmationPage);
    /*   var object={
         "img":this.base64Image,
         "success":true
       };
       this.rewardsCommonData.commonDataOfPhotos.push(object);
       console.log(this.rewardsCommonData);*/
     }, (err) => {

     });

   }


 showFlashLight(){
     if(this.flashLightAvalibleOrNo){
       this.platform.ready().then(() => {
         this.flashLight.switchOn().then(data=>{
           console.log(data);
         }).catch(err=>{
           console.log(err);
         });

       });
     }
   }

When I debug the code it’s going into catch for the method switchOn().With in the Catch method it’s getting err=""…

Please help me with this??

3 Likes

Same issue for me with ionic 5