Search code examples
appceleratorappcelerator-titaniumappcelerator-mobile

iOS: Camera & Gallery is launched even after denying permission


I am creating an application which is going to use camera and gallery to get photos. I am calling the Ti.Media APIs as mentioned and it is working good in happy scenarios. Now while testing I clicked on deny for accessing camera and gallery. Here are the outcomes:

Gallery

After I denied access to gallery, a black window was displayed with cancel on top right. Once I clicked cancel and again called Ti.Media to open gallery, it displayed a white window with a lock and text displaying then I need to enable access from the Privacy Settings.

Camera

After I denied access to camera, every time I call Ti.Media to launch camera, it displayed the camera UI (with the click round button) and a cancel button on lower left, but the view is all black.

My query is that is this normal behavior? Shouldn't the API return error that gallery and camera is not accessible and hence we can handle it properly in the application?

I am using 5.3.1.GA SDK and developing it for iOS 8.x and 9.x.


Solution

  • We need to use the following piece of code for the permission access:

    if (Ti.Media.hasCameraPermissions()) {
        return alert('You already have permission.');
    }
    
    Ti.Media.requestCameraPermissions(function(e) {
        if (e.success) {
            alert('You were granted permission.');
        } else {
            alert('You cannot access camera.');
        }
    });
    

    Place the required code instead of the alerts, respectively.