Delegate Binding Method

I am creating a binding library for binding the Objective-C framework.

I have the following delegate, which should add it to the ApiDefinition file, and then I need to implement it using my Xamarin.iOS application:

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

MMSDKDelegate:

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

IMMDelegate:

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

I need the required definition in the ApiDefinition file, and I need some sample code to call this method from my Xamarin.iOS application.

Update

The frame I'm dealing with communicates with the iPhone attached to read the ID card information, it has methods called on the reader, inserted / deleted, and the card inserted / removed.

I implemented the answer by @ cole-xia, but the problem is that the methods inside IMMDelegate never called when inserting a card reader or identifier. When I call ReadCardData() , it should call Started() , which will display the information saved with Inserted() , but the current result is that after calling ReadCardData() , the Started() method is called, but Inserted() and ReaderConnected() never called at any stage.

In the demo Framework application, it is used as follows (and works correctly):

 // 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 } } 

All suggestions are welcome and appreciated.

In general, I just need to do the same functionality of the demo application in the Xamarin.iOS application.

+5
source share
2 answers

Use Sharpie to Create an ApiDefinition

The result is on my side:

 // @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); } 

Using:

 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()); } 
+3
source

Along with Cola Xia's answer, you may also need to make sure that the integration of third-party SDKs requires some entries in the "Supported external accessory protocols" file of info.plist file.

Please check the Xcode sample and see if there is an entry for the "Supported external accessory protocols" key. If it is, you should add them to your Xamarin.iOS project info.plist file.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1273204/


All Articles