我正试图拍一张照片,我稍后会发送给一个宁静的服务。调试我发现当它退出imagePickerController函数时会产生段错误。
代码如下:
extension ViewController{
func imagePickerControllerDidCancel(_ picker:
UIImagePickerController) {
picker.dismiss(animated: true)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let selectedImage: UIImage? = info[UIImagePickerControllerEditedImage] as? UIImage
let originalImage: UIImage? = info[UIImagePickerControllerOriginalImage] as? UIImage
let imageData:Data = UIImagePNGRepresentation(originalImage!)!
let imageStr = imageData.base64EncodedData()
if let smallShoeImage = UIImageJPEGRepresentation(originalImage!, 0.1) {
print ("smallShoeImage = ", smallShoeImage)
SendImagetoML(shoeImage: originalImage!)
picker.dismiss(animated: true, completion: nil)
}
}//imagePickerController
func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
view.alpha = 1.0
}
} //extension
如果我注释掉了imagePickerController中的所有内容,它仍然会生成一个段错误。
这是段错误: https://imgur.com/gallery/UO3ll
当您离开imagePickerControllerDelegate函数时会发生段错误,但它似乎捕获了图像,我可以在以后使用它,但我认为不应该发生段错误。
我的班级定义如下:
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, LoginButtonDelegate{
var picker = UIImagePickerController()
据我所知,一切都很正常但是当我离开imagePickerController时我得到了segFault所以我一定错过了什么。我还测试过:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
但是这是Swift早期版本的委托,如果我使用它,它永远不会被调用。带有XCode 9.1的iOS 11(iOS 11所需的版本必须升级)。
任何提示都非常感谢。