ios - 在 iphone 模拟器上使用 UIImagePickerController

标签 ios camera ios-simulator uiimagepickercontroller photo-gallery

我有方法,从画廊或相机拍照

-(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];
}

但是当我在模拟器上运行它时,代码不起作用。它在 picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbumpicker.sourceType = UIImagePickerControllerSourceTypeCamera

中不起作用

是模拟器的问题还是代码的问题?

最佳答案

试试这个,

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

如果您正在为 iPad 创建应用程序。您必须在 popOver 控件中显示图库。

关于ios - 在 iphone 模拟器上使用 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9172918/

相关文章:

iphone - 我们可以在模拟器中检查推送通知吗?

ios - 在 OS X 10.10 (Yosemite Beta) 中,如何使用 iOS 6.1 模拟器进行测试?

ios - 输入附件 View 显示在像 UIAlertController 这样的对象上

ios - UITableViewCell 内的 UICollectionView 断言失败

ios - Rx swift : Complex TextFields Validation

iOs 注册来自相机胶卷的通知

android - 如何将对 "video/photo"附加的支持从 whatsapp 等应用程序添加到我的应用程序?

xcode - 如何在 Xcode 中为不同的配置填充不同的 Info.plist

ios - Swift 1.2 中的 Variadic @autoclosure?

iOS8 对尚未渲染的 View 进行快照会导致快照为空