Trying to detect then prompt for camera access permissions on ios failing, cant ask for permission

Trying to detect then prompt for camera access permissions on ios but the code below.

The output from IsCameraAllowed() is “Camera Access Disabled” because the followign is coming back as false.

if ( native.canShowPopup( "requestAppPermission" ) ) then

local function isValueInTable( haystack, needle )

assert( type(haystack) == “table”, “isValueInTable() : First parameter must be a table.” )

assert( needle ~= nil, “isValueInTable() : Second parameter must be not be nil.” )

for key, value in pairs( haystack ) do

if ( value == needle ) then

return true

end

end

return false

end

– Helper function that lets us know that we can use media.capturePhoto().

local function canUseMediaCapturePhoto()

– Ensure that can use the camera.

local hasAccessToCamera, hasCamera = media.hasSource( media.Camera )

if ( not hasCamera ) then

print( “Device does not have a camera!” )

return false

elseif ( not hasAccessToCamera ) then

print( “Lacking camera permission!” )

return false

end

– Ensure that we have permission to use external storage. We do not need

– to check for camera permission explicitly, because media.hasSource does that

– for us (see hasAccessToCamera above).

local grantedPermissions = system.getInfo(“grantedAppPermissions”)

if ( grantedPermissions ) then

if ( not isValueInTable( grantedPermissions, “Storage” ) ) then

print( “Lacking storage permission!” )

return false

end

end

return true 

end

– Called when the user has granted or denied the requested permissions.

local function cameraPermissionsListener( event )

– Print out granted/denied permissions.

print( “cameraPermissionsListener( " … json.prettify( event or {} ) … " )” )

– Check again for camera (and storage) access.

– Note that we use our helper function, canUseMediaCapturePhoto(), as the

– permissions listed in the event are ONLY for what has been just denied

– or granted.

if ( canUseMediaCapturePhoto() ) then

–print( “Calling media.capturePhoto() from permissions listener!” )

–media.capturePhoto( { listener = sessionComplete } )

isAROk = true

textCameraOnOff.text = “Camera On”

arCameraCanvas.fill = { type = “camera” }

arCameraCanvas:toBack()

arCameraCanvas.isVisible = true

else

– The user hasn’t given us the required permissions.

– Tell the user to enable it in Settings.

native.showAlert( “Camera Access Required”, “The Augmented Reality mode requires you grant access to the camera. Please go to Settings and grant this app access to the Camera.”, { “OK” } )

– Turn off the camera swicth

onOffSwitch:setState( { isOn=false, isAnimated=true } )

isAROk = false

textCameraOnOff.text = “Camera Off”

arCameraCanvas.isVisible = false

arCameraCanvas:toBack()

arCameraCanvas.fill = { type = “none” }

end

end

– Attempt to access the camera.

– We can’t assume that the user has given us permission to use the camera.

local function IsCameraAllowed( event )

– Get access to the Camera!

local hasAccessToCamera, hasCamera = media.hasSource( media.Camera )

if ( canUseMediaCapturePhoto() ) then

– If we have access to the camera, capture a photo.

–print( “Calling media.capturePhoto() from tap listener!” )

–media.capturePhoto( { listener = sessionComplete } )

–native.showAlert( “All GooD”, “Start the AR.”, { “OK” } )

isAROk = true

textCameraOnOff.text = “Camera On”

arCameraCanvas.fill = { type = “camera” }

arCameraCanvas:toBack()

arCameraCanvas.isVisible = true

elseif ( hasCamera ) then

– If we don’t have access to the camera, and a camera is actually available,

– request permission to use it, if we can.

if ( native.canShowPopup( “requestAppPermission” ) ) then

local permissionsToRequest = nil

local rationaleTitleMessage = “media.capturePhoto() needs permissions!”

local rationaleMessage = nil

if system.getInfo( “platformName” ) == “Android” then

– On Android, we also need the Storage permission to use media.capturePhoto().

permissionsToRequest = { “Camera”, “Storage” }

rationaleMessage = “The camera is required to enable the Augmented Reality view!”

else

permissionsToRequest = { “Camera” }

rationaleMessage = “The camera is required to enable the Augmented Reality view!”

end

– Make the actual request from the user.

native.showPopup( “requestAppPermission”, {

appPermission = permissionsToRequest,

urgency = “Normal”,

rationaleTitle = rationaleTitleMessage,

rationaleDescription = rationaleMessage,

listener = cameraPermissionsListener,

} )

else

– The device has a Camera, but we can’t ask for permission to use it.

– Tell the user to enable it in Settings.

native.showAlert( “Camera Access Disabled”, “A camera was found on this device, but we do not have permission to use. Please go to Settings then grant this app access to the Camera.”, { “OK” } )

– Turn off the camera swicth

onOffSwitch:setState( { isOn=false, isAnimated=true } )

isAROk = false

textCameraOnOff.text = “Camera Off”

arCameraCanvas.isVisible = false

arCameraCanvas:toBack()

arCameraCanvas.fill = { type = “none” }

end

else

– The sample requires that we actually have a camera.

native.showAlert( “Camera Not Found”, “A camera device cannot be found on this device.  Augmented Reality mode will be disabled.”, { “OK” } )

– Turn off the camera swicth

onOffSwitch:setState( { isOn=false, isAnimated=true } )

isAROk = false

textCameraOnOff.text = “Camera Off”

arCameraCanvas.isVisible = false

arCameraCanvas:toBack()

arCameraCanvas.fill = { type = “none” }

end

return true

end

Above code may be for android so I added in and Android/IOS and this fro IOS but I still do not get a prompt appear

local options =

{

   appPermission = “Camera”,

   urgency = “Critical”,

   listener = iOSCameraPermissionsListener,

   rationaleTitle = “Camera access required”,

   rationaleDescription = “Camera access is required to take photos. Re-request now?”,

   settingsRedirectTitle = “Alert”,

   settingsRedirectDescription = “Without the ability to take photos, this app cannot properly function. Please grant camera access within Settings.”

}

native.showPopup( “requestAppPermission”, options )

Above code may be for android so I added in and Android/IOS and this fro IOS but I still do not get a prompt appear

local options =

{

   appPermission = “Camera”,

   urgency = “Critical”,

   listener = iOSCameraPermissionsListener,

   rationaleTitle = “Camera access required”,

   rationaleDescription = “Camera access is required to take photos. Re-request now?”,

   settingsRedirectTitle = “Alert”,

   settingsRedirectDescription = “Without the ability to take photos, this app cannot properly function. Please grant camera access within Settings.”

}

native.showPopup( “requestAppPermission”, options )