开发者

How do you bind to or invoke Foundation functions?

I'm interested in binding to iOS Foundation function开发者_运维知识库s as seen in the iOS documentation but there aren't any handles or instances to send a message to invoke them. How would I do this with MonoTouch? I would think that it would involve something within the MonoTouch.ObjCRuntime namespace.


All of MonoTouch's NS* objects implement the MonoTouch.ObjCRuntime.INativeObject interface which has a property getter called "Handle". This accessor is public on NSObject and all subclasses.

Edit: code to bind NSSetUncaughtExceptionHandler() will be something like this:

public delegate void NSUncaughtExceptionHandler (IntPtr exception);

[DllImport ("/System/Library/Frameworks/Foundation.framework/Foundation")]
extern static void NSSetUncaughtExceptionHandler (IntPtr handler);

Then you could use it like this:

static void MyUncaughtExceptionHandler (IntPtr exception)
{
    // Got an exception... 
}

static void Main (string[] args)
{
    NSSetMyUncaughtExceptionHandler (Marshal.GetFunctionPointerForDelegate(
        new NSUncaughtExceptionHandler(
            MyUncaughtExceptionHandler
        )
    );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜