简体   繁体   中英

Crash when choosing from the iphone photo album using monotouch

My application crashes completely (fatal error), showing the entire stacktrace and "Error connecting stdout and stderr. The weird thing is though, if I do not shut down the iPhone simulator, and I go through the workflow on my app a second time, there is no crash.

I tried both PhotoLibrary and SavedPhotosAlbum;

When picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary , everything works fine until it brings up the photo library. When you click the photo library to see the images inside, this is when the crash occurs.

When picker.SourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum , the album loads fine, and I can even select an image. After I select an image, I can edit the image, etc...Once I'm done and hit Choose. It crashes.

Again, after it crashes, I can go through the workflow and it gets through just fine.

This is very strange. Any ideas?

Thanks.

I had this exact same problem; it turns out the ImagePickerController object was being garbage collected, are you declaring the property inside of a method (eg a button touch event?). I found if I declared the property at the start of the class then it solved this problem. Code sample:

UIImagePickerController picker;

//snip

void HandlePhotoBtnTouchUpInside(object sender, EventArgs e)
{
    picker = new UIImagePickerController();
    ImagePickerDelegate imgDel = new ImagePickerDelegate();
    picker.Delegate = imgDel;

    picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
    PresentModalViewController(imagePicker, true);
}

The ImagePickerDelegate Class is pretty simple, I've only overridden the FinishedPickingMedia method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM