Search code examples
ioscameraios-simulatoruiimagepickercontrollerphoto-gallery

Use the UIImagePickerController on a iphone simulator


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?


Solution

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