Type Function Library media.* Return value Boolean Revision 2017.3060 Keywords media, camera, photo library See also media.selectPhoto() media.capturePhoto()
Determines if the given media source, such as a camera or photo library, is available on the platform. This function should be called before calling media.selectPhoto() or media.capturePhoto() to determine if that media service is available. Returns true
if the media source is available on the platform/device. Returns false
if not.
media.hasSource( media.Camera )
returns two booleans. If the first boolean is true
, this means that the device has a camera and the app has permission to access it. If the second boolean is true
, this means that the device has a camera. With these two booleans, the following logic applies:
true
implies the second is true
.true
and the second being false
should not happen.false
and the second being true
means that the device has a camera, but the app does not have permission to access it.false
means the device does not have a camera.For media.hasSource( media.Camera )
, the first boolean will only be false
if the device does not have a camera, or the user has explicitly denied camera access to the app.
iOS will handle requesting permission to access the Camera or Photos the first time the user attempts this through the app.
media.hasSource( mediaSource )
Constant. Can be one of the following:
media.PhotoLibrary
media.Camera
media.SavedPhotosAlbum
local onComplete = function( event ) print( "Returned from camera view." ) end if ( media.hasSource( media.PhotoLibrary ) ) then media.selectPhoto( { mediaSource=media.PhotoLibrary, listener=onComplete } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end
local onComplete = function( event ) print( "Returned from camera view." ) end local hasAccessToCamera, hasCamera = media.hasSource( media.Camera ) if ( hasAccessToCamera == true ) then -- There is access to the camera media.capturePhoto( { listener = onComplete } ) elseif ( hasCamera == true and native.canShowPopup( "requestAppPermission" ) ) then -- A camera exists, but there is no access to it! native.showPopup( "requestAppPermission", { appPermission="Camera" } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end