开发者

How do I test a camera in the iPhone simulator?

Is there any way to test the iPhone camera in the sim开发者_如何学运维ulator without having to deploy on a device? This seems awfully tedious.


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


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.


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

How do I test a camera in the iPhone simulator?


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


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.


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.


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

Repo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜