How do I test a camera in the iPhone simulator?

IphoneIos Simulator

Iphone Problem Overview


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

Iphone Solutions


Solution 1 - Iphone

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 - Iphone

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 - Iphone

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

 iCimulator

Solution 4 - Iphone

Nope (unless they've added a way to do it in 3.2, haven't checked yet).

Solution 5 - Iphone

I wrote a replacement view to use in debug mode. It implements the same API and makes the same delegate callbacks. In my case I made it return a random image from my test set. Pretty trivial to write.

Solution 6 - Iphone

A common reason for the need of accessing the camera is to make screenshots for the AppStore.

Since the camera is not available in the simulator, a good trick ( the only one I know ) is to resize your view at the size you need, just the time to take the screenshots. You will crop them later.

Sure, you need to have the device with the bigger screen available.

The iPad is perfect to test layouts and make snapshots for all devices. Screenshots for iPhone6+ will have to be stretched a little ( scaled by 1,078125 - Not a big deal… )

Good link to a iOS Devices resolutions quick ref : http://www.iosres.com/


Edit : In a recent project, where a custom camera view controller is used, I have replaced the AVPreview by an UIImageView in a target that I only use to run in the simulator. This way I can automate screenshots for iTunesConnect upload. Note that camera control buttons are not in an overlay, but in a view over the camera preview.

The @Craig answer below describes another method that I found quite smart - It also works with camera overlay, contrarily to mine.

Solution 7 - Iphone

> Just found a repo on git that helps Simulate camera functions on iOS Simulator with images, videos, or your MacBook Camera.

Repo

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSheehan AlamView Question on Stackoverflow
Solution 1 - IphoneTimView Answer on Stackoverflow
Solution 2 - IphoneCraigView Answer on Stackoverflow
Solution 3 - IphonePenggunaView Answer on Stackoverflow
Solution 4 - IphonebpapaView Answer on Stackoverflow
Solution 5 - IphoneStefan ArentzView Answer on Stackoverflow
Solution 6 - IphoneMooseView Answer on Stackoverflow
Solution 7 - IphoneSiempayView Answer on Stackoverflow