swift - 添加了隐私 key ,但在关闭 UIImagePickerController 时仍然崩溃

标签 swift uiimagepickercontroller avcapturesession gpuimage

发疯了。

使用UIImagePickerController拍照, 呈现 pickerController 后,控制台打印 [MC] systemgroup.com.apple.configurationprofiles 路径的系统组容器为/private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles[MC] 读取自公共(public)有效用户设置。

应用程序在关闭 pickerController 1-2 秒后崩溃。 控制台显示 -[AVCaptureSession release]: message sent to deallocated instance 0x1c4201080

已添加隐私 key : enter image description here

及相关代码示例:

 func seletedImage()  {

    let alertAction = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
    alertAction.addAction(UIAlertAction.init(title: "拍照", style: .default, handler: { [weak self] (alertCamera) in
        self?.showImagePicker(sourceType: .camera)
    }))
    alertAction.addAction(UIAlertAction.init(title: "从相册中选择", style:.default, handler: { [weak self] (alertPhpto) in
        self?.showImagePicker(sourceType: .photoLibrary)
    }))
    alertAction.addAction(UIAlertAction.init(title: "取消", style: .cancel, handler: nil))

    self.present(alertAction, animated: true, completion: nil)
}

 func showImagePicker(sourceType: UIImagePickerControllerSourceType) {

    if UIImagePickerController.isSourceTypeAvailable(sourceType) == false {
        if sourceType == .camera { print("未授予使用相机权限") }
        if sourceType == .photoLibrary { print("未授予访问相册权限") }
        return
    }

    let picker: UIImagePickerController = UIImagePickerController()
    picker.delegate = self as UIImagePickerControllerDelegate & UINavigationControllerDelegate
    picker.sourceType = sourceType
    picker.allowsEditing = false

    weak var weakself = self
    weakself?.present(picker, animated: true, completion: nil)
}

我是否遗漏了一些其他重要的配置? 也许与GPUImage相关?

非常感谢任何帮助。

PS。即使我不拍照直接取消也会崩溃。 photoLibrary 类型工作正常。

最佳答案

请处理相机不可用的情况。请使用下面的代码

func  SelectFromCamera()  {

    //Camera
    let cameraMediaType = AVMediaTypeVideo
    AVCaptureDevice.requestAccess(forMediaType: cameraMediaType) { granted in
        if granted {
            print("Granted access to \(cameraMediaType)")
            if UIImagePickerController.isSourceTypeAvailable(
                UIImagePickerControllerSourceType.camera) {
                let imagePicker = UIImagePickerController()
                imagePicker.delegate = self
                imagePicker.sourceType =
                    UIImagePickerControllerSourceType.camera
                imagePicker.mediaTypes = ["public.image"]
                //  imagePicker.allowsEditing = false
                self.present(imagePicker, animated: true,
                             completion: nil)
            }
        } else {
            //open app setting if not authorize to access camera
            print("Denied access to \(cameraMediaType)")
        }
    }
}

关于swift - 添加了隐私 key ,但在关闭 UIImagePickerController 时仍然崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587269/

相关文章:

ios - 图像在从相机拍摄时旋转,即使是 JPEG 格式

ios - imagePickerController设置UIImageView.image不改变图片显示

audio - AVCaptureSession 音频样本以与 AVAudioSession 采样率不同的频率捕获

ios - 我如何访问 firebase .ref 闭包内部的变量并在外部使用它们

ios - 函数已创建,但从未调用过,但仍会执行

ios - AVAssetWriter::append() 返回 false,没有额外信息(How to do segmenting of captured input to video-chunks with AVFoundation?)

ios - 使用 AVCaptureDevice 读取条形码,我想在扫描后立即显示动画 ActivityIndi​​cator

ios - countDownTimer = 0 的 UIDatePicker 显示 "0 hours 1 min"

swift - 单元格的大小不等于 Collection View 的大小

ios - 调用 UIPinchGestureRecognizer 后更改 UIView 的边界