When you develop for iOS, you can quickly add third-party libraries to your NativeScript projects via the CocoaPods dependency manager.
To work with such libraries, you need to wrap them as a custom NativeScript plugin and add them to your project.
You need to install CocoaPods. If you haven't yet, you can do so by running:
$ sudo gem install cocoapods
NOTE: All operations and code in this article are verified against CocoaPods 0.38.2.
To check your current version, run the following command.
$ pod --version
To update CocoaPods, just run the installation command again.
sudo gem install cocoapods
To start, create a project and add the iOS platform.
$ tns create MYCocoaPods
$ cd MYCocoaPods
$ tns platform add iosFor more information about working with NativeScript plugins, click here.
cd ..
mkdir my-plugin
cd my-plugin
Create a package.json file with the following content:
{
"name": "myplugin",
"version": "0.0.1",
"nativescript": {
"platforms": {
"ios": "1.3.0"
}
}
}
Create a Podfile which describes the dependency to the library that you want to use. Move it to the platforms/ios folder.
my-plugin/
├── package.json
└── platforms/
└── ios/
└── Podfile
Next, install the plugin:
tns plugin add ../my-plugin
tns build ios
This modifies the MYCocoaPods.xcodeproj and creates a workspace with the same name.
IMPORTANT: You will no longer be able to run the
xcodeprojalone. NativeScript CLI will build the newly created workspace and produce the correct .ipa.