Search code examples
javascriptiospaypalnativescriptbraintree

How to integrate platform dependent SDKs in Nativescript on the corresponding OS


I want to try integrating the Braintree SDKs into an existing NativeScript-Mobile App. Since the SDKs are only available for their native platforms, I thought about using the NS-Marshalling to execute platform-dependent the SDK on the corresponding OS.

Since I am pretty sure that it will not work that easy, I thought about two possibilities: Implementing the modules platform dependent in the corresponding language (e.g. iOS - Objective-C/Swift) like mentioned on the Braintree sides (https://developers.braintreepayments.com/start/hello-client/ios/v3) and integrate them platform dependend from NativeScript (I inmagine it like a module, I say use this list of objects and I receive a "payment successful" or "payment failed" response). The OS-Dependend module would then do the rest (evaluations, SDK interaction and so on).

Another approach was to marshal every single piece of code into JS modules and execute the JS-module platform dependent. What I am missing is simply the possibility to integrate the module, since I have no idea, how I should import and access the "-Library via JavaScript (I don't even think that this is possible).

What do you think about this approaches? Is it possible to do it one way or another?


Solution

  • You can use the native libraries (e.g CocoaPods, dynamic and static libraries for iOS and *.aar and *.jar for Android) in NativeScript and access them through JavaScript/TypeScript. The best approach, in my opinion, would be to create a NativeScript plugin and expose the needed functionality via JavaScript/TypeScript by using data conversion (marshalling for iOS) (and here the respective article for Android)

    As recommended by Android you can also add dependencies to a library through the gradle file