我正在创建一个使用 Socket Mobile 的 SocketScan SDK 的 Xamarin ios 应用程序。创建了一个绑定项目,将静态库转换为 dll。但无法使用 SktClassFactory.CreateScanObject() 方法创建 ISktScanObject 实例。由于 System.MemberAccessException,该实例未完全创建。请看下面的代码
// A 1:1 of ApiHelper's Objective-C open: method
public void Open ()
{
_deviceInfoList.Clear ();
if (_noDeviceText != null) {
_deviceInfoList.Add (_noDeviceText, _noDeviceText);
}
if (_scanObjectReceived != null) {
SktClassFactory.ReleaseScanObject (_scanObjectReceived);
}
_scanObjectReceived = SktClassFactory.CreateScanObject (); //Two properties inside _scanObjectReceived are not getting created due to System.MemberAccessException.
Task.Run (() => InitializeScanAPIThread ());
_scanApiOpen = true;
}
以下是我在 _scanObjectReceived = SktClassFactory.CreateScanObject (); 行之后调试 _scanObjectReceived 对象时收到的异常消息;
- Msg System.MemberAccessException:无法创建 ScanAPI.ISktScanMsg 的实例,因为它是一个抽象类
- 属性 System.MemberAccessException:无法创建 ScanAPI.SktScanProperty 的实例,因为它是一个抽象类
绑定工程中ISktScanObject接口的ApiDefinition如下:
[Protocol, Model]
interface ISktScanObject {}
// @protocol ISktScanObject
[Protocol, Model]
[BaseType (typeof (NSObject))]
interface SktScanObject : ISktScanObject
{
// @required -(id<ISktScanMsg>)Msg;
[Abstract]
[Export ("Msg")]
ISktScanMsg Msg { get; }
// @required -(id<ISktScanProperty>)Property;
[Abstract]
[Export ("Property")]
SktScanProperty Property { get; }
}
绑定项目中 SktClassFactory 接口的 ApiDefinition 如下:
[BaseType (typeof(NSObject))]
interface SktClassFactory
{
// +(id<ISktScanObject>)createScanObject;
[Static]
[Export ("createScanObject")]
ISktScanObject CreateScanObject ();
// +(void)releaseScanObject:(id<ISktScanObject>)scanObj;
[Static]
[Export ("releaseScanObject:")]
void ReleaseScanObject (ISktScanObject scanObj);
// +(id<ISktScanApi>)createScanApiInstance;
[Static]
[Export ("createScanApiInstance")]
ISktScanApi CreateScanApiInstance ();
// +(void)releaseScanApiInstance:(id<ISktScanApi>)scanApi;
[Static]
[Export ("releaseScanApiInstance:")]
void ReleaseScanApiInstance (ISktScanApi scanApi);
// +(id<ISktScanDevice>)createDeviceInstance:(id<ISktScanApi>)scanApi;
[Static]
[Export ("createDeviceInstance:")]
ISktScanDevice CreateDeviceInstance (ISktScanApi scanApi);
// +(void)releaseDeviceInstance:(id<ISktScanDevice>)deviceInstance;
[Static]
[Export ("releaseDeviceInstance:")]
void ReleaseDeviceInstance (ISktScanDevice deviceInstance);
}
需要做什么才能正确实例化 _scanObjectReceived 对象。提前致谢。