gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:17:54 25 4
gpt4 key购买 nike

发疯了。

使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com