我指的是这个post
private static void MyUncaughtExceptionHandler(IntPtr exception)
{
// this is not working because NSException(IntPtr) is a protected constructor
var e = new NSException(exception);
// ...
}我如何在这里创建一个异常?
我该做点这样的事吗?
NSException exception = (NSException)ObjCRuntime.Runtime.GetNSObject(handle);发布于 2016-05-30 14:13:41
你自己找到了正确的答案:
NSException exception = (NSException) ObjCRuntime.Runtime.GetNSObject (handle);发布于 2016-05-30 13:40:17
一个选项是创建NSException的自定义子类并公开受保护的构造函数。你的ObjCRuntime.Runtime.GetNSObject也应该有效(我认为--不是100%肯定)。
您可以创建这样一个非常简单的子类:
public MyNSException : NSException {
public MyNSException(IntPtr handle) : base(handle) { }
}然后您应该能够像这样创建您的NSException:
var exception = new MyNSException(exception);我没有尝试使用这些代码,但这应该会让您编译。
https://stackoverflow.com/questions/37525472
复制相似问题