Declaring delegate methods in Cocoapod plugin


I’m trying to incorporate a Cocoapod interface into the iOS version of my app:

I’m confused about delegates. That cocoapod has 3 “delegate” methods:

func wrapperDidPress(_ imagePicker: ImagePickerController, images: [UIImage])
func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage])
func cancelButtonDidPress(_ imagePicker: ImagePickerController)

How do I declare those methods? Here is how I am presenting the view (after installing the cocoapod using these instructions:

var pickerController = new ImagePickerController();
var iosPage = frameModule.topmost().ios.controller;
var self = page.ios;
pickerController.delegate = self;
pickerController.imageLimit = 1;
iosPage.presentViewControllerAnimatedCompletion(pickerController, true, null);

Ive tried an extremely wide variety of things, but couldnt hack it. Most of the time I get this error:

-[UIView doneButtonDidPress:images:]: unrecognized selector sent to instance 0x7fc4e9892830

The closest I got was with the following code. That would call doneButtonDidPress, but images would be undefined.

    var myPickerController = ImagePickerController.extend({
        viewDidLoad: function() {

            console.log('view load');
        doneButtonDidPress(controller, images) {
            // Called when the extension is about to move from the inactive to active state.
            // This will happen when the extension is about to present UI.

            // Use this method to configure the extension and restore previously stored state.
    }, {

        name: "myPickerController",
        exposedMethods: {
            "doneButtonDidPress": {
                returns: interop.types.void

    var pickerController = new ImagePickerController();


Delegates can be confusing. It’s arguably the hardest thing on iOS to work with when building a plugin, but once you’ve implemented it once you can repeat the pattern for all others.

You can copy-paste-adjust the code from two of my plugins if you like: nativescript-numeric-keyboard and nativescript-performance-monitor


They are, indeed confusing. I’ve only been working with Typescript for a short while, and I’m having trouble going through the process of creating a seed. Eddy I watched your tutorial (, and while it helped me understand how to build a plugin, I still cant figure out how to utilize the APIs provided by the cocoapod in the plugin. This, for example, works in mynoice-image-picker.ios.ts file:

import {Common} from './noice-image-picker.common';
export class NoiceImagePicker extends Common {
    constructor() {

    public showPicker() {

Calling showPicker from the UI (a button) consoles ‘hi’. But this wont even compile:

import {Common} from './noice-image-picker.common';
export class NoiceImagePicker extends Common {
    constructor() {

    public showPicker() {
        let pickerController = new ImagePickerController();
        pickerController.imageLimit = 1;

Doing something something similar and utilizing the API that way in my app (see my original question) does work.


Do you have a repo I can clone and fool around with?





Work in progress, but getting there. Will do a PR to your repo:


Awesome thank you!!! I owe you a beer. Were you able to wire up the delegate methods?


:beers: delegate looks good. Will push in about an hour.


Thanks for your help! Problem though, I get this when i run npm run demo.ios:

1   0x10366a7cb NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
2   0x103d3f1ee ffi_closure_unix64_inner
3   0x103d3fb22 ffi_closure_unix64
4   0x104a5f10a -[UIViewController view]
5   0x10492763a -[UIWindow addRootViewControllerViewIfPossible]
6   0x104927d20 -[UIWindow _setHidden:forced:]
7   0x10493ab6e -[UIWindow makeKeyAndVisible]
8   0x103d3f97d ffi_call_unix64
9   0x1204e59d0
file:///app/tns_modules/nativescript-noice-image-picker/noice-image-picker.js:60:61: JS ERROR ReferenceError: Can't find variable: ImagePickerDelegate

JS ERROR ReferenceError: Can’t find variable: ImagePickerDelegate
Am I running the demo correctly?


Hey Dave,

Looks like you need to remove and re-add node_modules (rm -rf node_modules && npm i) as well as the platforms/ios folder.

BTW, please just open an issue on GitHub and ping me there, otherwise I may miss your replies.


Thanks so much Eddy you rock! You are now a contributor on

I appreciate the help :slight_smile:


Sweet plugin! Thank you for this @davecoffin and @Eddy!