Unfortunately Apple does not give developers access to the ambient light sensor on the top of it’s iOS devices (used to measure brightness and adjust the screens brightness accordingly), and when I say access I mean direct access to it’s output rather the proximity state that can be inferred from it. This leaves us with using the camera as the only way to measure the ambient light in the operating environment.
Something you may be wondering is, how do we measure light? What values can we use to represent it? The answer here is a value called candela. To paraphrase Wikipedia, candela is the power of a light source in a particular direction (in this case it is the direction of the iPhone’s camera). However candela is not a value we can use here, because we are not just focusing on 1 point on the camera, we are focusing on as many as we can. Therefore we get into luminance, which is candela per square metre.
To calculate the luminance of a particular pixel, we simply take the red, green and blue values (since it is a camera it should not contain any alpha values) and use the following formula to convert them into a grayscale pixel:

double luminance = r*0.299 + g*0.587 + b*0.114;

The reason these values are weighted is because pure red, green and blue are actually darker/lighter than each other, with green being the darkest and blue being the lightest (hence the discrepancy between the blue and green weightings). What we have actually done there is calculate a grayscale value for our pixel, but here’s the trick, grayscale is luminance. The only difference between grayscale and a luminance value for a picture is that it is from a pixel instead. To calculate the luminance over an entire image, you simply take the mean of the luminance values for each pixel.
So in order to test this theory, 6 images will be used, 2 of night, 2 of twilight and 2 of day. The following code was used (using the UIImage pixel category I have previously made):

NSArray* dayArray = [NSArray arrayWithObjects:@"night",@"twilight",@"day",nil];
for(NSString* day in dayArray)
{
	for(int i=1;i<=2;i++)
	{
		UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png",day,i]];
		unsigned char* pixels = [image rgbaPixels];
		double totalLuminance = 0.0;
		for(int p=0;p<image.size.width*image.size.height*4;p+=4)
		{
			totalLuminance += pixels[p]*0.299 + pixels[p+1]*0.587 + pixels[p+2]*0.114;
		}
		totalLuminance /= (image.size.width*image.size.height);
		totalLuminance /= 255.0;
		NSLog(@"%@ (%d) = %f",day,i,totalLuminance);
	}
}

Below are the test images and there luminosity values:

Luminosity: 0.688431

Luminosity: 0.465598

Luminosity: 0.493491

Luminosity: 0.381365

Luminosity: 0.159368

Luminosity: 0.100030

As you can see these pictures all display different luminosities, the darker ones have less light power and the brighter ones have more (if it helps, imagine how much power a solar cell would generate as a function of luminance values). Now simply plug this logic into the iOS’s camera using the AVCaptureVideoDataOutput API and you can now measure the amount of ambient light. There is 1 problem, most iOS devices have cameras that auto adjust there brightness based on the amount of ambient brightness, this can tarnish results to make them slightly less accurate, however the adjustment is not enough to make the output from this kind of algorithm meaningless.

Links:
- Luminance of images
- RGB to Grayscale Conversion Calculator