Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17812] iOS: Feature Request to initiate the camera access prompt via Titanium Code

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-04-30T15:12:54.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0, Release 4.1.0
ComponentsiOS
Labelscamera, ios8, media
ReporterEduardo Gomez
AssigneeChee Kiat Ng
Created2014-10-01T15:36:23.000+0000
Updated2015-06-29T17:44:32.000+0000

Description

Feature Request

When building with the 3.4.0.GA TiSDK using the iOS 8 SDK on an iPhone 6 this issue is present. The issue is not that the prompt never shows but that its only triggered by launching the camera. If I want to prompt the user before I launch the camera there is no way to prompt the user. We would like to request the following features for Titanium 3.5.0 SDK: 1. Calling isCameraSupported() triggers the camera allowed prompt 2. If the user says Don't Allow calling isCameraSupported() again should return false, but its returning true which is incorrect.

Steps to reproduce

Build attached sample with environment specification

On the device go to settings > general > scroll to bottom, reset > reset Location & privacy

Launch the app and,

Click "is Camera supported" button

Notice that it returns 1 which is true

Click Launch Camera (Notice that a prompt is shown asking for access to the camera.

Click Dont allow

Take a picture and accept it

Notice that the picture is black

Accept the picture

Click is Camera Supported

Notice that it returns 1 which is true.

Notes

The user did not allow camera access so the isCameraSupported should return false. Also the prompt to enable camera access should be triggered by the isCameraSupported call or some other call so that we can ask the user if they want to allow camera access before we launch the camera. Following my steps on step 4 isCameraSupported() returns a 1 that it is supported, and no prompt is shown. Then if you go to step 6 and launch image capture the prompt shows up but at that point the camera is being launched. We need to be able to trigger the prompt on the isCameraSupported call. Now in step 7 click the Dont Allow button and take a picture of the black area, notice its black. Now accept or close the image capture viewfinder. Click as stated in step 11 isCameraSupported(). Notice that its still a 1 which indicates that the camera is supported even though the user has not allowed access.

Attachments

FileDateSize
3.4_Camera_Access_Prompt.zip2014-10-01T15:36:23.000+00004869321

Comments

  1. Chee Kiat Ng 2015-04-29

    Another PR option here: https://github.com/appcelerator/titanium_mobile/pull/6811 4_0_X: https://github.com/appcelerator/titanium_mobile/pull/6812

    Sample Code

       var win1 = Titanium.UI.createWindow({
       	backgroundColor: 'white'
       });
       
       var button1 = Titanium.UI.createButton({
       	title: 'is camera supported',
       	top: "20%"
       });
       
       var button2 = Titanium.UI.createButton({
       	title: 'is camera authorized',
       	top: "40%"
       });
       var button3 = Titanium.UI.createButton({
       	title: 'request camera access',
       	top: "60%"
       });
       
       var button4 = Titanium.UI.createButton({
       	title: 'open camera',
       	top: "80%"
       });
       
       button1.addEventListener('click', function(e) {
           var isCameraSupported = Ti.Media.isCameraSupported;
           var alert = Ti.UI.createAlertDialog({
               title: 'Is Camera Supported?',
               message: isCameraSupported
           });
           alert.show();  
       });
       
       button2.addEventListener('click', function(e) {
       	if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
       	    var cameraAuthorizationStatus = Ti.Media.cameraAuthorizationStatus;
       	    var theMsg;
       	    if (cameraAuthorizationStatus === Ti.Media.CAMERA_AUTHORIZATION_AUTHORIZED) {
       	    	theMsg = 'approved';
       	    };
       	    if (cameraAuthorizationStatus === Ti.Media.CAMERA_AUTHORIZATION_DENIED) {
       	        //at one point of time the user denied camera access
       	    	theMsg = 'Camera access was denied, please go to phone settings to give access';
       	    };
       	    if (cameraAuthorizationStatus === Ti.Media.CAMERA_AUTHORIZATION_RESTRICTED) {
       	    	theMsg = 'restricted';
       	    };
       	    if (cameraAuthorizationStatus === Ti.Media.CAMERA_AUTHORIZATION_NOT_DETERMINED) {
       	    	theMsg = 'not determined';
       	    	//althernatively, you can immediately call requestCameraAccess here
       	    };
       	    var alert = Ti.UI.createAlertDialog({
       	        title: 'Camera Authorization Status',
       	        message: theMsg
       	    });
       	    alert.show();  
       	}
       	else {
       		var alert = Ti.UI.createAlertDialog({
       	        title: 'IOS 7 or greater',
       	        message: 'only available for ios 7 and greater'
       	    });
       	    alert.show();
       	}
       });
       
       button3.addEventListener('click', function(e) {
       	if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
       		Ti.Media.requestCameraAccess(function(e) {
       			var theMsg;
       			if (e.success) {
       				theMsg = 'User granted access';
       			}
       			else {
       				theMsg = 'User denied access';
       			}
       
       		    var alert = Ti.UI.createAlertDialog({
       		        title: 'Camera request access',
       		        message: theMsg
       		    });
       		    alert.show();  
       		});
       	}
       	else {
       		var alert = Ti.UI.createAlertDialog({
       	        title: 'IOS 7 or greater',
       	        message: 'only available for ios 7 and greater'
       	    });
       	    alert.show();
       	}
       
       });
       button4.addEventListener('click', function(e) {
       	Ti.Media.showCamera();
       });
       
       win1.add(button1);
       win1.add(button2);
       win1.add(button3);
       win1.add(button4);
       
       win1.open();
       
  2. Eric Wieber 2015-06-29

    Verified fixed, using: MacOS 10.11 Studio 4.1.0.201506261427 Ti SDK 4.1.0.v20150626084425 Appc NPM 4.1.0-1 Appc CLI 4.1.0-4 Ti CLI 4.0.1 Alloy 1.6.2 Node v0.10.37 Java 1.7.0_45 Prompts for camera access via code is working as expected.

JSON Source