5

我正在创建一个绑定库来绑定本机 Objective-C 框架。

我有以下委托,我需要将其声明添加到 ApiDefinition 文件,然后我需要使用我的 Xamarin.iOS 应用程序来实现它:

- (void)Initialize:(id <MMSDKDelegate> _Nullable)pDelegate;

MMSDK委托:

@protocol MMSDKDelegate <IMMDelegate>
- (void)Started;
@end

IMMD 代表:

@protocol IMMDelegate
- (void)Inserted;
- (void)Removed;
- (void)ReaderConnected;
- (void)ReaderRemoved;
@end

我需要 ApiDefinition 文件中的所需定义,并且我需要一个示例代码来从我的 Xamarin.iOS 应用程序中调用此方法。

更新

我正在处理的框架是与 iPhone 附带的读卡器设备通信以读取 ID 卡信息,它具有在读卡器插入/移除和卡插入/移除时调用的方法..

我已经实现了@cole-xia 的答案,但问题是IMMDelegate当我插入读卡器或 ID 时,里面的方法永远不会被调用。当我调用时ReadCardData(),它应该调用Started()将显示保存的信息Inserted(),但当前结果是该Started()方法在调用之后被调用,ReadCardData()但在任何阶段都不会被调用。Inserted()ReaderConnected()

在框架的演示应用程序中,它被用作以下(并且可以正常工作):

// Demo app -> ViewController.m

@interface ViewController () <MMSDKDelegate>

@end


@implementation ViewController {
    MMSDK *sdkInstance;
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    sdkInstance = [MMSDK SharedInstance];
    [sdkInstance Initialize:self];
}


- (void)Started
{
    // Update UI by: reading in progress ..
}


- (void)Inserted
{
    // Update UI by: card inserted
    // And read card data
    [self readData:self];
}

- (void)Removed
{
    // Update UI by: card removed
}

- (void)ReaderConnected
{
    // Update UI by: card reader connected
}

- (void)ReaderRemoved
{
    // Update UI by: card reader removed
}


- (IBAction)readData:(id)sender
{
    var *data = [sdkInstance ReadCardData:YES pWithSignatureImage:YES pWithAddressData:YES];
    if (data.hasError) {
        // No data fetched
        return;
    }

    if (data) {
        // return card data
    }
}

欢迎和赞赏所有建议。

总之,我只需要在 Xamarin.iOS 应用程序中执行与演示应用程序相同的功能。

4

2 回答 2

3

使用Sharpie创建 ApiDefinition

我这边的结果:

// @protocol IMMDelegate
[BaseType (typeof (NSObject))]
[Protocol, Model]
interface IMMDelegate
{
    // @required -(void)Inserted;
    [Abstract]
    [Export ("Inserted")]
    void Inserted ();

    // @required -(void)Removed;
    [Abstract]
    [Export ("Removed")]
    void Removed ();
}

// @protocol MMSDKDelegate <IMMDelegate>
[BaseType (typeof (NSObject))]
[Protocol, Model]
interface MMSDKDelegate : IMMDelegate
{
    // @required -(void)Started;
    [Abstract]
    [Export ("Started")]
    void Started ();
}

// @interface ACR : NSObject
[BaseType (typeof(NSObject))]
interface YourClass
{
    // -(void)Initialize:(id<MMSDKDelegate> _Nullable)pDelegate;
    [Export ("Initialize:")]
    void Initialize ([NullAllowed] MMSDKDelegate pDelegate);
}

用法:

class MyDelegate : MMSDKDelegate {
    public void Started()
    {
    }

    public override void Removed()
    {
    }
    public override void Inserted()
    {
    }
}


//In ViewController

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    YourClass yourClass = new YourClass();
    yourClass.Initialize(new MyDelegate());
}
于 2017-11-09T02:25:43.250 回答
1

除了 Cola Xia 的回答,您可能还需要确保,这种第三方设备 SDK 集成需要 info.plist 文件的"Supported external accessory protocols"密钥中的一些条目。

请检查 XCode 示例并检查是否有"Supported external accessory protocols"密钥条目。如果存在,则应将它们添加到 Xamarin.iOS 项目的 info.plist 文件中。

我希望这可能会有所帮助!

于 2017-12-27T09:31:59.517 回答