按照這里的例子:JSContext我收到以下異常:{TypeError: myCSharpObject.myFunc is not a function. (In 'myCSharpObject.myFunc()', 'myCSharpObject.myFunc' is undefined)} 我的代碼如下: JSContext _context; _context = new JSContext(); var jsCallback = new MyJSExporter(); _context[(NSString)"myCSharpObject"] = JSValue.From(jsCallback, _context); var result = _context.EvaluateScript("myCSharpObject.myFunc();");協(xié)議定義為:[Protocol] interface IMyJSVisibleProtocol : IJSExport { [Export("myFunc")] int MyFunc(); [Export("Arity2:With:")] NSObject Arity2With(NSObject arg1, NSObject arg2); } class MyJSExporter : NSObject, IMyJSVisibleProtocol { public int MyFunc() { Console.WriteLine("Called!"); return 42; } public NSObject Arity2With(NSObject arg1, NSObject arg2) { Console.WriteLine("Arity 2 function called with " + arg1 + " " + arg2); return (NSNumber)42; } }異常處理程序?yàn)椋?nbsp; _context.ExceptionHandler = (context, exception) => { // {TypeError: myCSharpObject.myFunc is not a function. (In 'myCSharpObject.myFunc()', 'myCSharpObject.myFunc' is undefined)} };
Xamarin IOS 無法在 JavascriptCore 中綁定函數(shù)或回調(diào)
慕田峪9158850
2021-11-21 15:38:26