4

I've been running my app on a physical iOS device for a while now without any problem. But now UIImagePickerController view won't come up on the simulator. I've already saved photos to the simulator using the method here and have confirmed they do exist on the simulator in the image library. There are no errors popping up in Xcode. And I've tried playing around with different source types, but to no avail. Any idea what I might be doing wrong? Thank you much!

Code

    UIImagePickerControllerSourceType sourceType;
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
            {
                sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            }
            else
            {
                sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            }
            //Display photo library.
            [self startImagePickerControllerFromViewController: self
                                            usingDelegate: self
                                           withSourceType: sourceType];

...

- (BOOL)startImagePickerControllerFromViewController:(UIViewController*) controller
                                  usingDelegate:(id <UIImagePickerControllerDelegate,
                                                     UINavigationControllerDelegate>) delegate
                                 withSourceType:(UIImagePickerControllerSourceType) sourceType
{
    //Insure camera, controller, and delegate exist.
    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeCamera] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    //Create the ImagePicker.
    UIImagePickerController *imagePickerUI = [[UIImagePickerController alloc] init];
    imagePickerUI.sourceType = sourceType;
    //Only allow still images.
    imagePickerUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
    //Turn off editing.
    imagePickerUI.allowsEditing = NO;
    //Set the delegate.
    imagePickerUI.delegate = delegate;
    //Present the picker view.
    [controller presentViewController:imagePickerUI animated:YES completion:nil];

    return YES;
}
Community
  • 1
  • 1
golmschenk
  • 11,736
  • 20
  • 78
  • 137

1 Answers1

6
  if (([UIImagePickerController isSourceTypeAvailable:
      UIImagePickerControllerSourceTypeCamera] == NO)

The above condition ensures that the simulator cannot run it because the simulator does not have a camera.

Zia
  • 14,622
  • 7
  • 40
  • 59