ios - 如何限制用户在 iOS 应用程序中使用后置摄像头

标签 ios swift xcode cocoa-touch uiimagepickercontroller

我正在开发一个 iOS 应用程序,用户可以在其中拍照。但是,我希望用户只能使用前置摄像头。也就是说,他们不应该使用后置摄像头。目前,我的代码如下所示:

@IBAction func takePicture(sender: UIButton) {

    if UIImagePickerController.availableCaptureModesForCameraDevice(.Front) != nil {
        let imagePickerController = UIImagePickerController()
        imagePickerController.sourceType = .Camera
        imagePickerController.allowsEditing = false
        imagePickerController.cameraDevice = .Front
        imagePickerController.delegate = self
        presentViewController(imagePickerController, animated: true, completion: nil)
    }
    else {
        let alertVC = UIAlertController(
            title: "No Camera",
            message: "Sorry, this device has no camera",
            preferredStyle: .Alert)
        let okAction = UIAlertAction(
            title: "OK",
            style:.Default,
            handler: nil)
        alertVC.addAction(okAction)
        presentViewController(alertVC,
                              animated: true,
                              completion: nil)
    }
}

虽然这默认摄像头是前置的,但它仍然为用户提供了切换到后置摄像头的选择。有什么方法可以限制此功能?

提前致谢

最佳答案

如果您不想让用户享有 UIImagePickerController 提供的自由,就不要使用 UIImagePickerController。设计您自己的拍照界面(通过 AVFoundation),在其中完全掌控。

关于ios - 如何限制用户在 iOS 应用程序中使用后置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38493364/

相关文章:

ios - 列出 Cocos2D 应用程序中所有事件节点/ Action /动画

ios - AsWebAuthenticationsession 是否支持通用链接?

ios - 如果 App delegate 想要使用主 Storyboard文件,它必须实现 window 属性

ios - 如何根据 subview 的高度设置堆栈 View 的高度?

c++ - 是否可以使用 cmake 为没有 pod 的 Xcode 11 链接 xcframework (FirebaseCore.xcframework)?我找不到例子

ios - 转到当前 View UItableView

ios - 网络连接丢失 - Error Domain=kCFErrorDomainCFNetwork Code=-1005 - 在 GET 响应中

ios - 如果它们在表中,我如何使用 hitTest 获取底层 View ?

ios - 如何快速将分钟添加到当前时间

ios - 如何让这个垂直空间更加紧密?