简体   繁体   English

UIImagePickerController在iOS设备上工作但在iOS模拟器上没有?

[英]UIImagePickerController working on iOS device but not on iOS simulator?

I've been running my app on a physical iOS device for a while now without any problem. 我一直在物理iOS设备上运行我的应用程序一段时间没有任何问题。 But now UIImagePickerController view won't come up on the simulator. 但是现在UIImagePickerController视图不会出现在模拟器上。 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. 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;
}
  if (([UIImagePickerController isSourceTypeAvailable:
      UIImagePickerControllerSourceTypeCamera] == NO)

The above condition ensures that the simulator cannot run it because the simulator does not have a camera. 上述条件确保模拟器无法运行它,因为模拟器没有摄像头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM