nstudio / nativescript-camera-plus

MIT License
79 stars 50 forks source link

IOS Cannot set default camera #109

Open matty0005 opened 4 years ago

matty0005 commented 4 years ago

I am trying to implement the nativescript-camera-plus plugin and I want to have the front camera be the only option available. I have tried setting the default camera usingdefaultCamera="front", but this has no effect. I have also tried the toggleCamera() function, but that also seems to do nothing. The only way I am able to switch cameras is by double tapping the camera preview.

Here is a sample of my code

<CameraPlus height="100%" verticalAlignment="top" :visibility="showCamera" ref="CameraPlus"  id="camPlus"
                    defaultCamera="front"
                    saveToGallery="true"      
                    showCaptureIcon="false"
                    showGalleryIcon="false"
                    showToggleIcon="false"       
                    showFlashIcon="false"
                    debug="true"
                    enableVideo="false"
                    confirmVideo="false"
                    doubleTapCameraSwitch="false" 
                    @loaded="onCameraLoaded"
                    @photoCapturedEvent="photoCaptured($event)"
                    @errorEvent="onCameraError">     
                </CameraPlus>
onCameraLoaded(result) {
                this.cam = result.object;
                //Have tried this.cam.toggleCamera();
},

takePhotoButton() {
                this.image = this.cam.takePicture({ saveToGallery: false });               
                //This code and the code from photoCaptured work just fine.
            },

Any help would be appreciated

kriefsacha commented 3 years ago

Did you managed to make it work @matty0005 ?

matty0005 commented 3 years ago

@kriefsacha it's been a while since I worked on this project, but from what I remember I came up with a work-around.

I'd have to dig through my code to see what I did exactly, but it was something along the lines of setting the default camera to the rear, then after a short delay (something like 100ms), once the camera had been loaded, I would toggle the camera. This is all while the double tab switch option was disabled.

It seemed to work just fine and didn't run into many issues when testing it.