我刚收到一条imagePickerController:picker: didFinishPickingMediaWithInfo
的孤立崩溃报告,其中包含EXC_BREAKPOINT
消息(我理解通常在强制解包nil值时发生)。崩溃的代码是:
public func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
dismissViewControllerAnimated(true, completion: nil)
picker.delegate = nil
// ...do something with pickedImage...
}
我假设我需要检查是否已经像这样返回了UIImage:
public func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
dismissViewControllerAnimated(true, completion: nil)
picker.delegate = nil
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
// ...do something with pickedImage...
}
else {
// Show unsupported media type error dialog
}
}
我将选取器媒体类型设置为图像:
picker.mediaTypes = [kUTTypeImage as String]
所以我很惊讶didFinishPickingMediaWithInfo
正在返回UIImage以外的东西。任何想法为什么或可能会返回什么?