发疯。
使用 UIImagePickerController 拍照, 呈现pickerController之后,cosole打印 [MC] systemgroup.com.apple.configurationprofiles路径的系统组容器是/private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 和 [MC]公开的有效用户设置。
在关闭pickerController 1-2秒后,应用程序崩溃。 并且控制台显示-[AVCaptureSession版本]:发送到已释放实例0x1c4201080
的消息和相关代码示例:
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 类型可以正常工作。
答案 0 :(得分:0)
请处理相机不可用的情况。请使用以下代码
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)")
}
}
}