How do I test a camera in the iPhone simulator?

Is there any way to test the iPhone camera in the simulator without having to deploy on a device? This seems awfully tedious.


Solution 1:

There are a number of device specific features that you have to test on the device, but it's no harder than using the simulator. Just build a debug target for the device and leave it attached to the computer.

List of actions that require an actual device:

  • the actual phone
  • the camera
  • the accelerometer
  • real GPS data
  • the compass
  • vibration
  • push notifications...

Solution 2:

I needed to test some custom overlays for photos. The overlays needed to be adjusted based on the size/resolution of the image.

I approached this in a way that was similar to the suggestion from Stefan, I decided to code up a "dummy" camera response.

When the simulator is running I execute this dummy code instead of the standard "captureStillImageAsynchronouslyFromConnection".

In this dummy code, I build up a "black photo" of the necessary resolution and then send it through the pipelined to be treated like a normal photo. Essentially providing the feel of a very fast camera.

CGSize sz = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) ? CGSizeMake(2448, 3264) : CGSizeMake(3264, 2448);
UIGraphicsBeginImageContextWithOptions(sz, YES, 1);
[[UIColor blackColor] setFill];
UIRectFill(CGRectMake(0, 0, sz.width, sz.height));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

The image above is equivalent to a 8MP photos that most of the current day devices send out. Obviously to test other resolutions you would change the size.

Solution 3:

I never tried it, but you can give it a try! iCimulator

 iCimulator