Dear all,
I’m starting to developing an app in which I’m using the device’s camera. In the code for this app I used the standard code for taking a picture with the camera taken from the Samples > Camera app. In this Sample version the code is wrapped in a listener function that responds to a tap on the screen, as can be seen below. For my own app I removed this listener and just used:
My version:
if media.hasSource( media.Camera ) then
media.capturePhoto( { listener = sessionComplete } )
else
native.showAlert(“Corona”, “Camera not found.”)
end
From Samples > Camera
local listener = function( event )
if media.hasSource( media.Camera ) then
media.capturePhoto( { listener = sessionComplete } )
else
native.showAlert(“Corona”, “Camera not found.”)
end
return true
end
bkgd:addEventListener( “tap”, listener )
Now this both works in the Corona simulator. However when I install both on my device, only the Samples app works. When I open up my app, it gives “Camera not found”. Anyone any idea how it can be that the device camera is not found in my version? Or any reason why the camera can not be found?
For the completeness of my story I copied the rest of my code (mostly taken from the Samples code with some things commented) below. I hope you can help,
Thanks, Jules
Appendix - Rest of code:
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local _W = display.contentWidth
local _H = display.contentHeight
– Camera not supported on simulator.
local isXcodeSimulator = “iPhone Simulator” == system.getInfo(“model”)
if (isXcodeSimulator) then
local alert = native.showAlert( “Information”, “Camera API not available on iOS Simulator.”, { “OK”})
end
–
local bkgd = display.newRect( centerX, centerY, _W, _H )
bkgd:setFillColor( 0.5, 0, 0 )
local sessionComplete = function(event)
local image = event.target
– print( "Camera ", ( image and “returned an image” ) or “session was cancelled” )
– print( "event name: " … event.name )
– print( "target: " … tostring( image ) )
if image then
– center image on screen
image.x = centerX
image.y = centerY
end
end