1

我正在开发一个带有图片消息的聊天应用程序(支持纵向和横向方向),最近更新到 Swift 2.3。我遇到了这个问题,即关闭 UIImagePickerController 会导致应用程序因 EXC_BREAKPOINT 崩溃(在这两种情况下都是“使用照片”和“取消”),并且我一生都无法弄清楚是什么原因造成的。删除self.dismissViewControllerAnimated(true, completion: nil)线消除了崩溃(尽管将选择器留在屏幕上),所以我相信问题的根源就在那里。

这是我设置和调用 UIImagePicker 的方式:

let takePhotoAction = UIAlertAction(title: "Take a Photo", style: .Default, handler: { (alert: UIAlertAction!) -> Void in
            if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
                let imagePicker = UIImagePickerController();
                imagePicker.delegate = self
                imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
                self.presentViewController(imagePicker, animated: true, completion: nil)
            }
        })

以下是处理选择图像事件的方法。

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    self.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        let image = info[UIImagePickerControllerOriginalImage] as? UIImage
        if image != nil {
            print("Got image");
            uploadToS3(image!);
        }
          self.dismissViewControllerAnimated(true, completion: nil)
}

任何帮助,将不胜感激!

4

0 回答 0