Create Native Modules – React Native – Pinterest

Many a times in React Native App development stage, we come at a point when we want to add a features which is not in-built in react native but can be developed by native IOS or Android coding. At that stage we need to develop a Native Module for our app which allow us to extend the native features to react native.

Create a react native project “PinterestAuth” using command below :

Change directory to “ios” using the below command :

Now, using the command below, create a pod file

Open the Podfile and add the following dependency in the target section :

After saving the Podfile run the following command :

Now create a Pinterest app by going to this url and note down the APP ID for next steps.

Open project in XCode, right-click .plist file and select Open As > Source Code. Add the code below between  the <dict> </dict> tags :

Replace {your-app-id} with APP ID generated above.

Next, In file AppDelegate.m add the code below :

Right click on “PinterestAuth” folder and create a new Cocoa Touch Class with name “PinterestManage”. Now, we have two files PinterestManager.h and PinterestManager.m.

In the PinterestManager.h add the code below :

Next, we will add the code below to PinterestManager.m :

In the above code we are creating a Pinterest instance using the instance we are getting the token that is generated after user authenticates and return the token as a promise . In case, there is error, we reject with the error message.

Now, open file index.ios.js and add the code below :

Video Tutorial