Use the UIImagePickerController on a iphone simulator

Eugene Trapeznikov picture Eugene Trapeznikov · Feb 7, 2012 · Viewed 16.8k times · Source

I have the method, that take photos from gallery or from the camera

-(IBAction) getPhoto:(id) sender {
  UIImagePickerController * picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;

  if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
  } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  }

  [self presentModalViewController:picker animated:YES];
}

But when i run it on the simulator, code doesnt work. And it doesnt work in picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum and picker.sourceType = UIImagePickerControllerSourceTypeCamera

Is the problem in the simulator or in the code?

Answer

Krrish picture Krrish · Feb 7, 2012

Try this,

 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        }
        else
        {
            picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        }
        [self.navigationController presentModalViewController:picker animated:NO];

If you are creating the app for iPad. You will have to present the gallery in a popOver control.