我在 UIImagePickerController 选择中遇到问题。当我从照片库应用程序崩溃中选择源时,由于从自由列表中退出的指针的签名无效。那么如果我再次运行它使用相同的代码工作正常。我在谷歌搜索并发现了一个与我的查询Xcode - My app crash and the error is "Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug"相关的问题。
但解决办法在我的案例中不起作用。
我正在使用Xcode 8.1,我的部署目标是8.0。
答案 0 :(得分:1)
正如@luke要求提供UIImagePickerViewController
的代码:
let pickerView = UIImagePickerController()
pickerView.delegate = self
pickerView.allowsEditing = true
pickerView.sourceType = .photoLibrary
let authStatus = PHPhotoLibrary.authorizationStatus() // Get the current authorization state.
// print(authStatus)
if (authStatus == PHAuthorizationStatus.notDetermined) {
// Access has not been determined.
PHPhotoLibrary.requestAuthorization({ (newStatus) in
if (newStatus == PHAuthorizationStatus.authorized) {
self.present(pickerView, animated: true, completion: { _ in })
}
else {
}
})
} else if authStatus == PHAuthorizationStatus.authorized {
print("Access has been granted.")
self.present(pickerView, animated: true, completion: { _ in })
} else if (authStatus == PHAuthorizationStatus.denied) {
print("Access has been denied.")
}
else if (authStatus == PHAuthorizationStatus.restricted) {
print("Restricted access - normally won't happen.")
}
现在,当用户选择特定图像时: 将调用此方法:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
//print(info)
if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
YOUR_GLOBAL_IMAGE_VIEW?.contentMode = .scaleAspectFit
YOUR_GLOBAL_IMAGE_VIEW?.image = pickedImage
}
}
dismiss(animated: true, completion: nil)
}
不要忘记导入PhotosUI
和UIImagePickerControllerDelegate
。