Use Obj-C with TypeScript + Angular


#1

Hello, I’ve been trying hard to add a static native 3rd party SDK in obj-c to my project and use it within my NS project.

So far I’ve added the sdk.framework file into my app/app_resources/ios/frameworks/ I don’t know if this folder is correct but it seems to compile (tns build and run) into the deployed app. Now the problem is: how can I use the obj-c code in my TypeScript project? Can someone provide samples?

I’ve seen somewhere some usages but I don’t know how to import it to my .ts files and use it. This is getting pretty hard so far and I’ve spent a lot of effort without any success around this.

edit: for example purposes let’s say I’ve the object foo() in my obj-c framework and want to use it in the .ts file.

Thank you.


#2

This doc article might give you some help: https://docs.nativescript.org/runtimes/ios/how-to/Use-Native-Libraries


#3

That doesn’t help. Already checked that. I needed an easy way to import and use a static 3rd party library into my NS project, which I couldn’t find any example and spend a lot of time researching on how to get it done without any kind of success.

Ended up moving to Flutter and get it done with ease “out-of-the-box”. Still, I’d thank to anyone that could provide a sample / steps to solve this.

Thank you.


#4

You could wrap your static library into static framework (with module.modulemap file generated). An example of how module.modulemap file should look can be found here. One possible solution to visualize the structure of a plugin using static framework you could use as a reference nativescript-ui-gauge.

`npm i nativescript-ui-gauge

And then navigate to node_modules/nativescript-ui-gauge/platforms/ios folder

You will notice the TNSGauge.framework file has two separate folders Headers and Modules. In the Headers all the *.h files should be located and in the Modules is where you should put your module.modulemap file.

The static framework is part of the plugin and can be accessed directly in the source code based on the exposed classes, methods. properties, interfaces, etc. (it is always a great advantage if the library/framework do have public API reference or if you generate a *.d.ts declaration files as described here). For example take a look at the file node_modules/nativescript-ui-gauge/ui-gauge.ios.js and see how the native code is called with marshalling

For example, converted JavaScript call will look like the following

TKRadialGauge.alloc().init();