Create NativeScript Plugin using IOS Static Library issue

Issue

I have created .a static library (tested in Xcode for native ios project and Its working fine)
Now I am following this https://github.com/NativeScript/nativescript-plugin-seed to create nativescript plugin using .a static framework.

Plugin structure
enter image description here

module.modulemap file is created by me and it’s look like this

module libstaticlibrary {
    umbrella header "staticlibrary.h"
    export *
}

staticlibrary.h

#import <Foundation/Foundation.h>

@interface staticlibrary : NSObject
+ (NSString *)sayHello;
@end

libstaticlibrary.d.ts also created by me

declare class staticlibrary extends NSObject {

    static sayHello():string;

}

Then in helloplugin.common.ts I am trying to access staticlibrary.sayHello() method.

export class Utils {
  public static SUCCESS_MSG(): string {
    // let msg = `Your plugin is working on ${app.android ? 'Android' : 'iOS'}.`;
    let msg = staticlibrary.sayHello();

    setTimeout(() => {
      dialogs.alert(`${msg} For real. It's really working :)`).then(() => console.log(`Dialog closed.`));
    }, 2000);

    return msg;
  }

I am getting following error.

node_modules/nativescript-helloplugin/helloplugin.common.ts(21,15): error TS2304: Cannot find name 'staticlibrary'.

What is I am doing wrong here?

Solution

It’s just the TypeScript compiler error, you have to generate typings for your static library (refer docs to know how) or just add this line at top of your file.

declare var staticlibrary: any

I see that you do have a declaration file in your code snippet, if you want to use it you have to include it to your references.d.ts file.

Answered By – Manoj

Answer Checked By – Senaida (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.