使用带有UIImagePickerController的presentModalViewController在iOS 5上导致崩溃 [英] Using presentModalViewController with UIImagePickerController causing Crash on iOS 5
问题描述
使用带有UIImagePickerController的presentModalViewController导致iOS 5上的崩溃(它在版本< 5上正常运行),我试图获取设备上的所有相册,使用'UIImagePickerControllerSourceTypeSavedPhotosAlbum'只获取相机图像,所以当我更改sourceType为'UIImagePickerControllerSourceTypePhotoLibrary'它崩溃,我感谢任何帮助,这是我的代码:
Using presentModalViewController with UIImagePickerController causing Crash on iOS 5 (its running fine on version<5), i am trying to get all the albums on the device, using 'UIImagePickerControllerSourceTypeSavedPhotosAlbum' is only getting the Camera images, so when i change the sourceType to 'UIImagePickerControllerSourceTypePhotoLibrary' it crashes, i appreciate any help, here is my code:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if(version < 5)
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
else
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imgPicker animated:YES];
推荐答案
来自官方文件:
要使用包含其默认控件的图像选择器控制器,请执行以下步骤:
To use an image picker controller containing its default controls, perform these steps:
-
验证设备是否能够从所需来源中挑选内容。这样做是调用isSourceTypeAvailable:class方法,从UIImagePickerControllerSourceType枚举中提供一个常量。
Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the "UIImagePickerControllerSourceType" enum.
检查哪些媒体类型可用,对于源类型''通过调用availableMediaTypesForSourceType:class方法重新使用。这使您可以区分可用于视频录制的摄像机和仅可用于静止图像的摄像机。
Check which media types are available, for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.
告诉图像选择器控制器进行调整根据您要提供的媒体类型 - 静态图像,电影或两者 - 通过设置mediaTypes属性来显示UI。
Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the mediaTypes property.
通过以下方式显示用户界面调用presentViewController:animated:completion:当前活动视图控制器的方法,将配置的图像选取器控制器作为新视图控制器传递。
Present the user interface by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller.
在iPad上,显示用户界面使用弹出窗口。仅当图像选择器控制器的sourceType属性设置为UIImagePickerControllerSourceTypeCamera时,这样做才有效。要使用弹出控制器,请使用UIPopoverController类参考中演示和解除弹出窗口中描述的方法。
On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in "Presenting and Dismissing the Popover" in UIPopoverController Class Reference.
当用户点击按钮选择新捕获或保存的图像或电影,或取消操作,使用您的委托对象关闭图像选择器。对于新捕获的媒体,您的代表可以将其保存到设备上的相机胶卷。对于以前保存的媒体,您的代表可以根据您应用的目的使用图像数据
When the user taps a button to pick a newly-captured or saved image or movie, or cancels the operation, dismiss the image picker using your delegate object. For newly-captured media, your delegate can then save it to the Camera Roll on the device. For previously-saved media, your delegate can then use the image data according to the purpose of your app
也许第4点引起了麻烦。
Maybe point 4 is causing troubles.
这篇关于使用带有UIImagePickerController的presentModalViewController在iOS 5上导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!