tags:

views:

17905

answers:

3

It seems obvious that some people have been able to figure out how to access the iPhone camera through the SDK (Spore Origins, for example), but I haven't been able to find any helpful information. I don't want anyone to violate their NDA, but does anyone know of any existing (official) resources that show how this can be done? Thanks.

+18  A: 

You need to use the UIImagePickerController class, basically:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = pickerDelegate
picker.sourceType = UIImagePickerControllerSourceTypeCamera

The pickerDelegate object above needs to implement the following method (EDIT This is now deprecated, see below):

- (void)imagePickerController:(UIImagePickerController *)picker
                 didFinishPickingImage:(UIImage *)image
                 editingInfo:(NSDictionary *)editingInfo;

Within the body of that method the image object is the data from the camera which you can then use for your specific application.

EDIT

In iPhone OS 3.0 didFinishPickingImage is deprecated, so instead you'll need to implement:

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

The dictionary info will contain entries for the original, and the edited image, keyed with UIImagePickerControllerOriginalImage and UIImagePickerControllerEditedImage respectively. (see http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImagePickerControllerDelegate_Protocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html for more details)

wxs
Fantastic. Thank you.
Jason Francis
The picker delegate method you mention here is now deprecated in OS 3.0 - http://tinyurl.com/yjlhzcl
barfoon
+2  A: 

Hmmmm.....Ever tried using an OverlayView? With this the camera might look customized but in actuality its just a view above it.

If the private API's are directly accessed it might result in the app being rejected by Apple. See if the below link helps.

link text

black2842