Skip to content
nrocy edited this page Sep 14, 2010 · 14 revisions

Table of Contents

  1. How it works
  2. Usage and example

How it works

1. The camera is enabled by modifying the simulator plists.
2. A call is made to:

-(void)mockCameraWithImageURL:(NSString*)url delay:(NSInteger)delay;

This sets up an NSTimer that will fire after delay seconds. The timer handler will pull the image from the given URL, and present it to this delegate method:

- (void)imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)info

Usage and example

1. Modify your simulator plist files

Locate the plist files for the simulator(s) that you want to change, for me these are:

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/System/Library/CoreServices/SpringBoard.app/simulator.plist
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/CoreServices/SpringBoard.app/simulator.plist

As the iPad doesn’t have a camera it makes no sense to enable it – but if you want to, also change:

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/CoreServices/SpringBoard.app/iPadSimulator.plist
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/System/Library/CoreServices/SpringBoard.app/iPadSimulator.plist

Open each of the plist files in the Property List Editor:

  1. Expand Root
  2. Add a new child to the capabilities dictionary, Key: “still-camera”, Type “Boolean”, Value: Ticked
  3. Save the plist file

You’ll probably need to copy the plist files somewhere else to be able to change them, then copy them back.

2. Include the category in your application

#ifdef DEBUG
#import "UIImagePickerController+SimulatedCamera.h"
#endif

3. Tell the category which image to present as the newly captured image

  UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;
  picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  picker.showsCameraControls = YES;

#ifdef DEBUG
  [picker mockCameraWithImageURL:@"http://localhost/test.jpg" delay:2.0];
#endif

  [self presentModalViewController:picker animated:YES];

  [picker release];

The default delay is 2 seconds, if not specified.