0

If my program wants to have a feature which need to access Camera and take photo and come back to app using UIImagePicker (UIImagePickerControllerSourceTypeCamera), can my program do that on iPhone, especially on non-jailbroken device? Does Apple allow for such program to upload in AppStore? I have seen somewhere that Apple don't allow this(camera access from 3rd party app) if we create such a program. Is it so?

Appreciate your suggestions.

Thanks.

-Prabakar.

Stella
  • 1,728
  • 5
  • 41
  • 95

1 Answers1

1

You use UIImagePickerController directly:

UIImagePickerController *thePicker = [[UIImagePickerController alloc] init];
thePicker.delegate = thePickerDelegate;
thePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

//Here you would present thePicker modally, and release it after this
//It will be deallocated when you remove it from screen
[anotherViewController presentModalViewController: thePicker animated:NO];
[thePicker release];

In the thePickerDelegate, implement

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

The image is the picture you took, and you can manipulate it as you wish. If you want the UIImagePickerController to dissapear after taking one photo, this is where you would trigger this action, and remove it from screen, in the modal case presented above, by calling

[thePicker dismissModalViewControllerAnimated: NO];
luvieere
  • 37,065
  • 18
  • 127
  • 179
  • Thanks. Doesn't it a leak if we leave 'thePicker'? – Stella Nov 17 '09 at 20:01
  • If we leave it where? Please explain where you believe to be a leak. – luvieere Nov 17 '09 at 20:06
  • I am asking where do we need to release 'thePicker' if we allocate like below? Can i release it in end of 'didFinishPickingImage'? UIImagePickerController *thePicker = [[UIImagePickerController alloc] init]; – Stella Nov 17 '09 at 20:07
  • Oh, I see, well, I didn't write the whole showing the picker - releasing the picker part, because you may want to add it to a navigation controller, a tab bar, as a child of another view, or display it modally. Of course that you should release it after adding it to the screen one way or another. – luvieere Nov 17 '09 at 20:19
  • I've edited my answer to include the modal presentation and removal of the picker. – luvieere Nov 17 '09 at 20:25