ios - 针对 iOS 6+ 时是否需要检查相机是否存在?

标签 ios ios6 camera avfoundation

我正在制作一个在多个区域使用摄像头的应用程序,我突然想到所有支持 iOS 6+ 的设备都有一个摄像头。这更像是一个编程实践问题,而不是一个实际的实现问题。

Apple 从未明确建议您检查摄像头,但许多开发人员会这样做。

不检查安全吗? 检查摄像头有什么影响?

有什么性能优势/劣势吗?

谢谢,

维林德博拉

最佳答案

来自 UIImagePickerController isSourceTypeAvailable: 方法的文档:

Because a media source may not be present or may be unavailable, devices may not always support all source types. For example, if you attempt to pick an image from the user’s library and the library is empty, this method returns NO. Similarly, if the camera is already in use, this method returns NO.

Before attempting to use an UIImagePickerController object to pick an image, you must call this method to ensure that the desired source type is available.

所以是的,Apple 确实会告诉您进行检查。再说,做起来有多难:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
    // show camera
} else {
    // don't show camera
}

关于ios - 针对 iOS 6+ 时是否需要检查相机是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20448264/

相关文章:

ios - 在 Swift 3.0 中将观察者添加到 NotificationCenter 时遇到问题

ios - 如何检查 UILabel 是否为空并将内容附加到标签?

iphone - MPMovieViewController 不自动旋转

ios - 如何使用某种形式的数据持久性将文本类型数据保存在我的应用程序中

ios - iOS 中的裁剪视频在视频周围看到奇怪的绿线

ios - UIDatePickerView 问题,因为更新到 ios 8

ios - 从 View 模型结构中获取值

android - libgdx 为什么舞台摄像机不动?

iphone - 如何编辑plist文件中特定的NSDictionary?

java - 如何在安卓模拟器中使用电脑摄像头