이 작업을 수행합니다. 앱 실행시 SetupExceptionHandling() 메서드를 호출합니다. 마술은 NSRunLoop 부분입니다. 그러나 그 시점에서 예측할 수없는 영향으로 앱이 이상한 상태가 될 것입니다. 따라서 사용자가 예외를 처리하기로 결정한 후에 (예 : 다시 던지기) 앱을 종료하는 것이 좋습니다.
public static class IOSStartupTasks {
private static bool _HaveHandledException;
public static void HandleException(object sender, UnhandledExceptionEventArgs e) {
if (!(_HaveHandledException)) {
_HaveHandledException = true;
UIAlertView alert = new UIAlertView("Error", "Bad news", "report", "just crash");
alert.Delegate = whatever; // delegate object should take the exception as an argument and rethrow when it's done handling user input.
alert.Show();
NSRunLoop.Current.RunUntil(NSDate.DistantFuture); // keeps the app alive, but likely with weird effects, so make sure you don't let the user back into the main app.
}
}
public static void SetupExceptionHandling() {
AppDomain domain = AppDomain.CurrentDomain;
domain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
IOSStartupTasks.HandleException(sender, e);
}
}
이것은 실제로 원래 질문을 다루지 않습니다. –