Skip to content

Commit e1917f4

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #914 from NativeScript/fatme/cocoapod-article
Cocoapods.md
2 parents 72ed98f + 5ddb9a3 commit e1917f4

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

CocoaPods.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Using CocoaPods
2+
3+
When you develop for iOS, you can quickly add third-party libraries to your NativeScript projects via the [CocoaPods](https://cocoapods.org/) dependency manager.
4+
5+
To work with such libraries, you need to wrap them as a custom NativeScript plugin and add them to your project.
6+
7+
* [Install CocoaPods](#install-cocoapods)
8+
* [Create CLI Project](#create-cli-project)
9+
* [Wrap the Library as NativeScript Plugin](#wrap-the-library-as-nativescript-plugin)
10+
* [Build the Project](#build-the-project)
11+
12+
## Install CocoaPods
13+
You need to install CocoaPods. If you haven't yet, you can do so by running:
14+
15+
```
16+
$ sudo gem install cocoapods
17+
```
18+
> **NOTE:** All operations and code in this article are verified against CocoaPods 0.38.2.
19+
20+
To check your current version, run the following command.
21+
22+
```
23+
$ pod --version
24+
```
25+
26+
To update CocoaPods, just run the installation command again.
27+
28+
```
29+
sudo gem install cocoapods
30+
```
31+
32+
## Create CLI Project
33+
To start, create a project and add the iOS platform.
34+
35+
```bash
36+
$ tns create MYCocoaPods
37+
$ cd MYCocoaPods
38+
$ tns platform add ios
39+
```
40+
41+
## Wrap the Library as NativeScript Plugin
42+
43+
For more information about working with NativeScript plugins, click [here](PLUGINS.md).
44+
45+
```
46+
cd ..
47+
mkdir my-plugin
48+
cd my-plugin
49+
```
50+
51+
Create a package.json file with the following content:
52+
53+
```
54+
{
55+
"name": "myplugin",
56+
"version": "0.0.1",
57+
"nativescript": {
58+
"platforms": {
59+
"ios": "1.3.0"
60+
}
61+
}
62+
}
63+
```
64+
65+
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.
66+
67+
```
68+
my-plugin/
69+
├── package.json
70+
└── platforms/
71+
└── ios/
72+
└── Podfile
73+
```
74+
75+
Next, install the plugin:
76+
77+
```
78+
tns plugin add ../my-plugin
79+
```
80+
81+
## Build the project
82+
83+
```
84+
tns build ios
85+
```
86+
87+
This modifies the `MYCocoaPods.xcodeproj` and creates a workspace with the same name.
88+
89+
> **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.

0 commit comments

Comments
 (0)