I’m trying to test for front and back cameras separately in my code. I wrote what I thought was a nice test using cameraSource() only to find that on an iPad 1, this returns an error message rather than nil as I’d hoped. Will appreciate any suggestions.
Also, the docs say cameraSource() will return CAMERA_FRONT or CAMERA_BACK but it actually seems to return a 1 or 2.
@DaveW Normally a function will return a number value. That number corresponds to a name. If you print(CAMERA_FRONT) and print(CAMERA_BACK) they will print 2 and 1. Normally you would do something like “if cameraSource() == CAMERA_FRONT then something”
@dave1707 The following code seems to work on an iPad 1. No clue why. Not pretty but I’m not going to argue with success at this point. I haven’t been able to test it on a device with only 1 camera. Thanks for pointing me in the right direction.
FrontCamera = false
BackCamera = false
if cameraSource() ~= nil then
cameraSource(CAMERA_FRONT)
if cameraSource() == CAMERA_FRONT then
FrontCamera = true
end
cameraSource(CAMERA_BACK)
if cameraSource() == CAMERA_BACK then
BackCamera = true
end
end