预编译的静态库在xamarin ios中无法正常工作

时间:2018-03-19 07:36:09

标签: ios xamarin xamarin.forms xamarin.ios

我有一个预编译的静态库,用于扫描Scanner中的指纹。我可以轻松地将命令提供给扫描仪,它连接到我的应用程序,但我没有得到库的响应。库

没有执行覆盖方法

这是ApiDefinitions.cs文件的代码:

using System;

using UIKit;
using Foundation;
using ObjCRuntime;
using CoreGraphics;

namespace ScanningLibrary
{
[BaseType(typeof(NSObject))]
interface IdentiFI_45
{
    // -(void)setDelegate:(id)newDelegate;
    [Export("setDelegate:")]
    void SetDelegate(NSObject newDelegate);

    // -(void)connect;
    [Export("connect")]
    void Connect();

    // -(void)disconnect;
    [Export("disconnect")]
    void Disconnect();

    // -(void)setFpPowerOn;
    [Export("setFpPowerOn")]
    void SetFpPowerOn();

    // -(void)setFpPowerOff;
    [Export("setFpPowerOff")]
    void SetFpPowerOff();

    // -(void)getFpPowerStatus;
    [Export("getFpPowerStatus")]
    void GetFpPowerStatus();

    // -(void)startCaptureOneFinger;
    [Export("startCaptureOneFinger")]
    void StartCaptureOneFinger();

    // -(void)startCaptureTwoFinger;
    [Export("startCaptureTwoFinger")]
    void StartCaptureTwoFinger();

    // -(void)startCaptureRollFinger;
    [Export("startCaptureRollFinger")]
    void StartCaptureRollFinger();

    // -(void)getWSQEncodedFingerprintImage;
    [Export("getWSQEncodedFingerprintImage")]
    void GetWSQEncodedFingerprintImage();

    // -(void)cancelCapture;
    [Export("cancelCapture")]
    void CancelCapture();

    // -(void)getBatteryLevel;
    [Export("getBatteryLevel")]
    void GetBatteryLevel();

    // -(void)getDeviceSerialNumber;
    [Export("getDeviceSerialNumber")]
    void GetDeviceSerialNumber();

    // -(void)getFirmwareVersion;
    [Export("getFirmwareVersion")]
    void GetFirmwareVersion();

    // -(NSString *)getLibraryVersion;
    //[Export ("getLibraryVersion")]
    //[Verify (MethodToProperty)]
    //string LibraryVersion { get; }

    // -(void)getModelNumber;
    [Export("getModelNumber")]
    void GetModelNumber();

    // -(void)getReaderDescription;
    [Export("getReaderDescription")]
    void GetReaderDescription();
}

// @protocol IdentiFI_45_Delegate <NSObject>
[Protocol, Model]
[BaseType(typeof(NSObject))]
interface IdentiFI_45_Delegate
{
    // @required -(void)onConnection;
    [Abstract]
    [Export("onConnection")]
    void OnConnection();

    // @required -(void)onDisconnection;
    [Abstract]
    [Export("onDisconnection")]
    void OnDisconnection();

    // @required -(void)onSetFpPowerOn:(Boolean)fpPowerStatus;
    [Abstract]
    [Export("onSetFpPowerOn:")]
    void OnSetFpPowerOn(byte fpPowerStatus);

    // @required -(void)onSetFpPowerOff;
    [Abstract]
    [Export("onSetFpPowerOff")]
    void OnSetFpPowerOff();

    // @required -(void)onGetFpPowerStatus:(Boolean)fpPowerStatus;
    [Abstract]
    [Export("onGetFpPowerStatus:")]
    void OnGetFpPowerStatus(byte fpPowerStatus);

    // @required -(void)onLastFrame:(UIImage *)fpImage;
    [Abstract]
    [Export("onLastFrame:")]
    void OnLastFrame(UIImage fpImage);

    // @required -(void)onLastFrame:(NSData *)rawFpImageData withNFIQ:(int)nfiqScore;
    [Abstract]
    [Export("onLastFrame:withNFIQ:")]
    void OnLastFrame(NSData rawFpImageData, int nfiqScore);

    // @required -(void)onStreaming:(UIImage *)fpImage;
    [Abstract]
    [Export("onStreaming:")]
    void OnStreaming(UIImage fpImage);

    // @required -(void)onGetWSQEncodedFingerprintImage:(NSData *)wsqEncodedFingerprintImageData;
    [Abstract]
    [Export("onGetWSQEncodedFingerprintImage:")]
    void OnGetWSQEncodedFingerprintImage(NSData wsqEncodedFingerprintImageData);

    // @required -(void)onCancelCapture;
    [Abstract]
    [Export("onCancelCapture")]
    void OnCancelCapture();

    // @required -(void)onGetBatteryLevel:(float)level;
    [Abstract]
    [Export("onGetBatteryLevel:")]
    void OnGetBatteryLevel(float level);

    // @required -(void)onGetDeviceSerialNumber:(NSString *)serialNumber;
    [Abstract]
    [Export("onGetDeviceSerialNumber:")]
    void OnGetDeviceSerialNumber(string serialNumber);

    // @required -(void)onGetFirmwareVersion:(NSString *)version;
    [Abstract]
    [Export("onGetFirmwareVersion:")]
    void OnGetFirmwareVersion(string version);

    // @required -(void)onGetModelNumber:(NSString *)model;
    [Abstract]
    [Export("onGetModelNumber:")]
    void OnGetModelNumber(string model);

    // @required -(void)onGetReaderDescription:(NSString *)deviceDescription;
    [Abstract]
    [Export("onGetReaderDescription:")]
    void OnGetReaderDescription(string deviceDescription);
}

}

和struts.cs看起来像:     使用System;

namespace ScanningLibrary
{
}

视图中的实现Controller是

using System;
using CoreGraphics;
using UIKit;
using ScanningLibrary;
using Foundation;

namespace testController.iOS
{
public class CustomViewController : IdentiFI_45_Delegate
{

    IdentiFI_45 myIdentiFI_45_Device = new IdentiFI_45();

    readonly UIViewController parent;

    public CustomViewController(UIViewController parent)
    {
        this.parent = parent;
        ViewDidLoad();
    }

    public  void ViewDidLoad()
    {
        myIdentiFI_45_Device.SetDelegate(parent);


        parent.View.BackgroundColor = UIColor.White;
        parent.Title = "My Custom View Controller";

        var btn_Connect = UIButton.FromType(UIButtonType.System);
        btn_Connect.Frame = new CGRect(20, 100, 280, 44);
        btn_Connect.SetTitle("Connect", UIControlState.Normal);

        var btn_Disonnect = UIButton.FromType(UIButtonType.System);
        btn_Disonnect.Frame = new CGRect(20, 130, 280, 44);
        btn_Disonnect.SetTitle("DisConnect", UIControlState.Normal);

        var btn_Battery = UIButton.FromType(UIButtonType.System);
        btn_Battery.Frame = new CGRect(20, 160, 280, 44);
        btn_Battery.SetTitle("Get Battery Level", UIControlState.Normal);

        btn_Connect.TouchUpInside += (sender, e) =>
        {
            myIdentiFI_45_Device.Connect();
        };

        btn_Disonnect.TouchUpInside += (sender, e) =>
        {
            myIdentiFI_45_Device.Disconnect();
        };

        btn_Battery.TouchUpInside += (sender, e) =>
        {
            myIdentiFI_45_Device.GetBatteryLevel();
            myIdentiFI_45_Device.GetFpPowerStatus();

        };

        parent.View.AddSubview(btn_Connect);
        parent.View.AddSubview(btn_Disonnect);
        parent.View.AddSubview(btn_Battery);

    }

    public override void OnCancelCapture()
    {
        throw new NotImplementedException();
    }

    public override void OnConnection()
    {
        //throw new NotImplementedException();
    }

    public override void OnDisconnection()
    {
        throw new NotImplementedException();
    }

    public override void OnGetBatteryLevel(float level)
    {
        throw new NotImplementedException();
    }

    public override void OnGetDeviceSerialNumber(string serialNumber)
    {
        throw new NotImplementedException();
    }

    public override void OnGetFirmwareVersion(string version)
    {
        throw new NotImplementedException();
    }

    public override void OnGetFpPowerStatus(byte fpPowerStatus)
    {
        throw new NotImplementedException();
    }

    public override void OnGetModelNumber(string model)
    {
        throw new NotImplementedException();
    }

    public override void OnGetReaderDescription(string deviceDescription)
    {
        throw new NotImplementedException();
    }

    public override void OnGetWSQEncodedFingerprintImage(NSData wsqEncodedFingerprintImageData)
    {
        throw new NotImplementedException();
    }

    public override void OnLastFrame(UIImage fpImage)
    {
        throw new NotImplementedException();
    }

    public override void OnLastFrame(NSData rawFpImageData, int nfiqScore)
    {
        throw new NotImplementedException();
    }

    public override void OnSetFpPowerOff()
    {
        throw new NotImplementedException();
    }

    public override void OnSetFpPowerOn(byte fpPowerStatus)
    {
        throw new NotImplementedException();
    }

    public override void OnStreaming(UIImage fpImage)
    {
        throw new NotImplementedException();
    }

 }
}

1 个答案:

答案 0 :(得分:0)

正如@SushiHangover所说,您错误地使用了IdentiFI_45_Delegate

此方法SetDelegate应设置为IdentiFI_45_Delegate,但您要将其分配给UIViewController

解决方案:

public class CustomViewController : IdentiFI_45_Delegate
{

    IdentiFI_45 myIdentiFI_45_Device = new IdentiFI_45();

    public void ViewDidLoad()
    {
        myIdentiFI_45_Device.SetDelegate(this);
        btn_Connect.TouchUpInside += (sender, e) =>
        {
            myIdentiFI_45_Device.Connect();
        };
        //xxx
    }

    //Delegate Method 
    public override void OnConnection()
    {            
    }
}