我正在开发一个应用程序,它可以从 iDevice 的相机中捕获图像并将其上传到 Web 服务。
没问题,除了设备的相机外,一切正常。设备的相机让我发疯。我正在使用下面的代码来允许用户捕获图像。有时相机显示预览,有时不显示。而不是预览只是在屏幕上显示完全黑暗。如果我从后置摄像头切换到前置摄像头开始工作正常。我什至尝试从设备中删除所有后台应用程序并尽可能多地清除内存;仍然没有运气,我被困住了。:(
- (IBAction)addNewImage:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// Take picture from camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// set no to take as much pictures as user want.
imagePicker.showsCameraControls = YES;
// Show user the camera
[self presentModalViewController:imagePicker
animated:YES];
}
else
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker
animated:YES];
}
}