Does UIImagePickerController work on an iOS device, but not on an iOS simulator?

I’ve been running my application on an iOS physical device for some time without any problems. But now the UIImagePickerController view will not appear on the simulator. I already saved the photos in the simulator using the method here and confirmed that they exist on the simulator in the image library. There are no errors in Xcode. And I tried to play with different types of sources, but to no avail. Any idea what I can do wrong? Thank you very much!

the 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;
}
+4
source share
1 answer
  if (([UIImagePickerController isSourceTypeAvailable:
      UIImagePickerControllerSourceTypeCamera] == NO)

, , .

+6

Source: https://habr.com/ru/post/1538902/


All Articles