0
MonoTouch로 만든 iPad 응용 프로그램에 문제가 있습니다. "SelectPicture"메서드를 호출 한 후 "TakePicture"메서드를 호출하여 응용 프로그램이 중단됩니다. "parent.PresentModalViewController (picker, true);" "TakePicture"메서드를 반복적으로 호출하면 아무런 문제가 없습니다.Monotouch NSInvalidArgumentException 카메라
반환 된 오류 : "NSInvalidArgumentException 이유 : 응용 프로그램이 대상에 nil 모달보기 컨트롤러를 표시하려고했습니다.".
public static class Camera
{
static UIImagePickerController picker;
static Action<NSDictionary> _callback;
static UIPopoverController popover;
static void Init()
{
if (picker != null)
return;
picker = new UIImagePickerController();
picker.Delegate = new CameraDelegate();
}
public static void TakePicture (UIViewController parent, Action<NSDictionary> callback)
{
Init();
picker.SourceType = UIImagePickerControllerSourceType.Camera;
_callback = callback;
Console.WriteLine("Controller TEST");
parent.PresentModalViewController (picker, true);
}
public static void SelectPicture (UIViewController parent, Action<NSDictionary> callback)
{
if(Utils.isIpad()){
picker = new UIImagePickerController();
popover = new UIPopoverController(picker);
picker.Delegate = new CameraDelegate();
_callback = callback;
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
picker.ContentSizeForViewInPopover = new SizeF(parent.View.Frame.Width,parent.View.Frame.Height);
if(popover != null)
popover.PresentFromRect(new Rectangle(0,0,1000,1),
parent.View,UIPopoverArrowDirection.Any,true);
}else{
Init();
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
_callback = callback;
parent.PresentModalViewController (picker, true);
}
}
class CameraDelegate : UIImagePickerControllerDelegate {
public override void FinishedPickingMedia (UIImagePickerController picker, NSDictionary info)
{
var cb = _callback;
_callback = null;
picker.DismissModalViewControllerAnimated (true);
cb (info);
if(popover != null && popover.PopoverVisible){
popover.Dismiss(true);
popover.Dispose();
Console.WriteLine("DISPOSE");
}
picker.Dispose();
}
}
}
감사합니다.