how to implement interface from third party native api

I am integrating a few third party libraries and one of them is

Is there a way I can implement the interface from a native API in Uno? For example, here is a sample code in objective c, how can this (implementing interface part) be done in Uno?

There are other libraries that provide native (pre-built) ui components, however they require that the containing view/activity on each platform implement their specific interface to handle the values/events etc.

//  ViewController.m
//  ScanExample
//  Copyright (c) 2012 PayPal. All rights reserved.

#import "ViewController.h"

#import "CardIO.h"

@interface ViewController () <CardIOPaymentViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UILabel *infoLabel;


@implementation ViewController

#pragma mark - View Lifecycle
#pragma mark -

- (void)viewDidLoad {
    [super viewDidLoad];
    self.infoLabel.text = @"";

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [CardIOUtilities preload];

#pragma mark - User Actions

- (void)scanCardClicked:(id)sender {
    CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
    scanViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:scanViewController animated:YES completion:nil];

#pragma mark - CardIOPaymentViewControllerDelegate

- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
    NSLog(@"Scan succeeded with info: %@", info);
    // Do whatever needs to be done to deliver the purchased items.
    [self dismissViewControllerAnimated:YES completion:nil];

    self.infoLabel.text = [NSString stringWithFormat:@"Received card info. Number: %@, expiry: %02lu/%lu, cvv: %@.", info.redactedCardNumber, (unsigned long)info.expiryMonth, (unsigned long)info.expiryYear, info.cvv];

- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
    NSLog(@"User cancelled scan");
    [self dismissViewControllerAnimated:YES completion:nil];


Take a look at our docs on foreign code

Thanks Andres. I have already read through the docs.

I’ll rephrase my question, in the code example the View implements an interface called “CardIOPaymentViewControllerDelegate”.

#import "CardIO.h"

@interface ViewController () <CardIOPaymentViewControllerDelegate>

How can my Uno class definition specify this. For example:

[extern(iOS) ForeignInclude(Language.ObjC, "../Pods/CardIO/CardIO.h")]
public class CardIO // Can I just use : CardIOPaymentViewControllerDelegate here?

    public CardIO () {

Am I approaching this incorrectly, are there alternative ways of doing this?

Any response on this? Will appreciate if you can let me know if there is a way to achieve this.

Hey Ish!

I would recommend you to implement the interface in Objective-C, and call back to Uno code when necessary. To achieve that you can for example pass Uno delegates to your object when initialising it through foreign code.

Rough sketch:

ObjC.Object CreateMyObject(Action onSomeEvent)
    return [[MyObject alloc] initWithEventHandler:onSomeEvent];

Remember that delegates like Action are automatically converted to Obj-C blocks.

The Obj-C constructor would have a signature like the following:


It’d then hold on to the eventHandler and call it when some event is triggered.

It’s also possible to pass an Uno object to the Obj-C object and call methods on it using macros — refer to the foreign code docs.

Hope that helps!

Thanks, this is helpful. I will try this route.