Skip to content

Cocoapods.md #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions CocoaPods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Using CocoaPods

When you develop for iOS, you can quickly add third-party libraries to your NativeScript projects via the [CocoaPods](https://cocoapods.org/) dependency manager.

To work with such libraries, you need to wrap them as a custom NativeScript plugin and add them to your project.

* [Install CocoaPods](#install-cocoapods)
* [Create CLI Project](#create-cli-project)
* [Wrap the Library as NativeScript Plugin](#wrap-the-library-as-nativescript-plugin)
* [Build the Project](#build-the-project)

## Install CocoaPods
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
```

## Create CLI Project
To start, create a project and add the iOS platform.

```bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need an empty line before this one for proper rendering. (This applies to all code blocks.)

$ tns create MYCocoaPods
$ cd MYCocoaPods
$ tns platform add ios
```

## Wrap the Library as NativeScript Plugin

For more information about working with NativeScript plugins, click [here](PLUGINS.md).

```
cd ..
mkdir my-plugin
cd my-plugin
```

Create a package.json file with the following content:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't the touch package.json command create the package.json file? If so, make this "In the newly created package.json file, insert the following syntax."


```
{
"name": "myplugin",
"version": "0.0.1",
"nativescript": {
"platforms": {
"ios": "1.3.0"
}
}
}
```

Create a [Podfile](https://guides.cocoapods.org/syntax/podfile.html) 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
```

## Build the project

```
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 `xcodeproj` alone. NativeScript CLI will build the newly created workspace and produce the correct .ipa.