Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

handling camera permissions

$
0
0

Hi, I am using titanium classic. SDK 3.4.1. Teesting on iPhone 6 on iOs 8.1.

I have a function to showCamera and I'm trying to handle if the permission is not granted. Currently when I switch the camera position to false in settings, the following happens:

The camera opens up but the device can only see black. I am not getting into the onerror as expected. So I am unsure where in the code I can provide a prompt for the user to allow access to the camera.

code below:

function takePic(){
        Titanium.Media.showCamera({
 
        success:function(e) {
            console.log('in show camera function');
            if(e.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
 
                // Store the file in a variable 
                var image = e.media;
                ImageView.setImage(e.media);                    
                var oldWidth = e.media.width;
                var oldHeight = e.media.height;
 
                var setWidth=200;
                var newWidth = setWidth;
                var newHeight = (oldHeight/oldWidth)*newWidth;
                ImageView.setWidth(newWidth);
                ImageView.setHeight(newHeight);
                ImageViewvar=ImageView.toBlob();
                ImageView.setVisible(true);
                ImageUploaded = true;
                Upload_pic.setOpacity('1');
                Upload_pic.setEnabled(true);
                ImageViewResized = ImageFactory.imageAsResized(ImageViewvar, { width:newWidth, height:newHeight, quality:ImageFactory.QUALITY_HIGH });              
 
                //create a random name for the image
                tmpName = (new Date()).getTime().toString() + '.png';
                //create a folder where I will store the photo temporally
                g= Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'picturesToUpload');
                if (!g.exists()) {
                    // If the directory doesn't exist, make it
                    g.createDirectory();
                };
                photo = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'picturesToUpload', tmpName);
                photo.write(ImageViewResized);
 
            } else {
                alert("got the wrong type back ="+e.mediaType);
            }
        },
        error: function(e){
            alert(error.code);
            alert("Error accessing camera");
            Upload_pic.setOpacity('1');
            Upload_pic.setEnabled(true);
        },
        cancel: function(e){
            Upload_pic.setOpacity('1');
            Upload_pic.setEnabled(true);
        }
    });
 
    };

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>