如何在iOS swift中申请多项权限?

时间:2017-06-17 07:59:03

标签: ios swift xcode avcapturedevice

我正在使用相机在swift中进行录制。对于图​​像捕获图像,我只要求用户一个权限。但是对于视频,有两个权限Camera&麦克风。我正在检查相机的许可。我想用户应该能够录制视频,如果相机和相机麦克风权限已分配。

let mediaType = AVMediaTypeVideo
        let authStatus = AVCaptureDevice.authorizationStatus(forMediaType: mediaType)
        if authStatus == .authorized {
            // do your logic
            photoManager = PhotoManager(navigationController: self, allowEditing: true, imageOptions: .Camera, cameraOptions: .Image , callback: { (info) in

                if let info  = info {
                    self.recrdFromCamera(info: info)
                }
            })

        }
        else if authStatus == .denied {

            // denied
            Utility.showAlert(withTitle: ErrorMessage.CameraPermissions.title, message: ErrorMessage.CameraPermissions.message, okayTitle: Constant.ButtonName.settings, cancelTitle:Constant.ButtonName.cancel , okCall: {

            }, cancelCall: {

            })
        }
        else if authStatus == .restricted {
            // restricted, normally won't happen
            Utility.showAlert(withTitle: ErrorMessage.CameraPermissions.title, message: ErrorMessage.CameraPermissions.message, okayTitle: Constant.ButtonName.settings, cancelTitle:Constant.ButtonName.cancel , okCall: {

            }, cancelCall: {

            })
        }
        else if authStatus == .notDetermined {
            // not determined?!
            AVCaptureDevice.requestAccess(forMediaType: mediaType, completionHandler: {(_ granted: Bool) -> Void in
                if granted {
                    self.photoManager = PhotoManager(navigationController: self, allowEditing: true, imageOptions: .Camera, cameraOptions: .Image , callback: { (info) in

                        if let info  = info {
                            self.recrdFromCamera(info: info)
                        }
                    })

                }
                else {
                }
            })
        }
        else {
            // impossible, unknown authorization status
        }

0 个答案:

没有答案