0
我有興趣綁定到iOS基金會的功能,如在iOS documentation中所見,但是沒有任何句柄或實例可以發送消息來調用它們。我如何使用MonoTouch做到這一點?我認爲它會涉及MonoTouch.ObjCRuntime命名空間中的某些內容。你如何綁定到或調用基礎函數?
我有興趣綁定到iOS基金會的功能,如在iOS documentation中所見,但是沒有任何句柄或實例可以發送消息來調用它們。我如何使用MonoTouch做到這一點?我認爲它會涉及MonoTouch.ObjCRuntime命名空間中的某些內容。你如何綁定到或調用基礎函數?
MonoTouch的所有NS *對象都實現了MonoTouch.ObjCRuntime.INativeObject接口,該接口具有一個名爲「Handle」的屬性getter。該訪問器在NSObject和所有子類上是公共的。
編輯:代碼綁定NSSetUncaughtExceptionHandler()
將是這樣的:
public delegate void NSUncaughtExceptionHandler (IntPtr exception);
[DllImport ("/System/Library/Frameworks/Foundation.framework/Foundation")]
extern static void NSSetUncaughtExceptionHandler (IntPtr handler);
然後,你可以使用這樣的:
static void MyUncaughtExceptionHandler (IntPtr exception)
{
// Got an exception...
}
static void Main (string[] args)
{
NSSetMyUncaughtExceptionHandler (Marshal.GetFunctionPointerForDelegate(
new NSUncaughtExceptionHandler(
MyUncaughtExceptionHandler
)
);
}
你的建議的問題是,基金會的功能不屬於到任何類型的NSObject。它們更像全球功能。你能給我一個例子,說明如何調用像'NSSetUncaughtExceptionHandler'這樣的函數嗎? –
啊。非常感謝! –