<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abdullah Asendar on Medium]]></title>
        <description><![CDATA[Stories by Abdullah Asendar on Medium]]></description>
        <link>https://medium.com/@asendar?source=rss-449c9976a68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bHe92ha-QQ1QX2eX_tRBVA.jpeg</url>
            <title>Stories by Abdullah Asendar on Medium</title>
            <link>https://medium.com/@asendar?source=rss-449c9976a68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:15:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asendar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building React Native 0.61.5 SDK to be used by native IOS applications (Swift)]]></title>
            <link>https://asendar.medium.com/building-react-native-0-61-5-sdk-to-be-used-by-native-ios-applications-swift-481d38f549bb?source=rss-449c9976a68------2</link>
            <guid isPermaLink="false">https://medium.com/p/481d38f549bb</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[react-native-sdk]]></category>
            <dc:creator><![CDATA[Abdullah Asendar]]></dc:creator>
            <pubDate>Fri, 06 Nov 2020 18:12:31 GMT</pubDate>
            <atom:updated>2021-11-27T19:04:55.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mm8JucFufPWr2ls_I1h_0w.png" /></figure><p>I was trying to build a react native SDK to be used by native IOS and Android applications. Android was “Kinda” easy to do, but i faced some issues with IOS and thought sharing what i did may help somebody.</p><p>In this article we will build a simple react native SDK, and integrate that SDK into a native IOS application. The goal is to make it easy for the SDK user, we don’t want to bother the SDK users with npm or react native related stuff.</p><p>Lest get things started…</p><h3>Create React Native Project</h3><p>Either create a new react native project or use an existing one,</p><pre>react-native init MySdk --version 0.61.5</pre><h3><strong>Add Some dependencies</strong></h3><p>Naturally, we would need some dependencies for our SDK, dependancies that require linking. For this article we will be using:</p><p>— <a href="https://www.npmjs.com/package/react-native-fast-image">react-native-fast-image</a></p><pre>yarn add react-native-fast-image</pre><p>Finally install the pods</p><pre>npx pod-install ios</pre><h3><strong>Using FastImage</strong></h3><p>We are not going to do anything fancy on react native side, this is just a proof on concept. Just use the <strong>FastImage</strong> package that we added to make sure that it is working fine.</p><p><strong><em>App.js</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec5466173646abb5209cba2301ee8f10/href">https://medium.com/media/ec5466173646abb5209cba2301ee8f10/href</a></iframe><h3><strong>Create a native IOS wrapper for the React Native app</strong></h3><p>Running the created react native app is easy right? all you have to do is execute <strong><em>react-native run-ios</em></strong><em>. </em>But running it inside another native app is a different story.</p><p>First, create a native IOS wrapper (wraps the react native app), that will contain all the required pods by react native. The wrapper will also configure and start the react app.</p><p>The idea is to create a native IOS framework, which will hide all react native complexity inside it. First, go to Xcode and create a new Framework project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6RTrUz4JOaQp48KHruiKuQ.png" /></figure><p>In the next screen select a name for the framework and select <strong>Swift</strong> from the language dropdown. Let us name our framework <strong>MySdk-native</strong>.</p><p>After that open the terminal and cd into <strong>MySdk-native</strong> and execute:</p><pre>pod init &amp;&amp; pod install</pre><p>We now have a CocoaPods framework, close Xcode and open generated <strong>MySdk-native.xcworkspace</strong>.</p><p><strong>Next comes that hardest part, so buckle up!</strong></p><h3><strong>Preparing the dependency pods</strong></h3><p>Now we have to prepare the pod dependancies for our SDK. These dependencies include all React Native dependencies in addition to any dependency that requires linking (such as react-native-fast-image).</p><p><strong>React native</strong></p><p>React native pods are local pods, because they are downloaded using npm or yarn. So one option is to embed these dependencies inside the SDK, or even better, upload these pods to a <a href="https://guides.cocoapods.org/making/private-cocoapods.html">private podspec repo</a>.</p><p>The problem is, if we take the podspecs the way they are, upload them to a private podspec repo, the pods will not be installed correctly. To better understand what this means, let us take a look at one of react native’s dependencies, <strong>FBLazyVector. </strong>Its located at <strong><em>node_modules/react-native/Libraries/FBLazyVector/FBLazyVector.podspec.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dff2b57c579b341dd925d00f134e0c5/href">https://medium.com/media/2dff2b57c579b341dd925d00f134e0c5/href</a></iframe><p>As you can see:<br> — The podspec requires package.json to get the version and license.<br> — The source is set to <a href="https://github.com/facebook/react-native.git">https://github.com/facebook/react-native.git</a><br> — source_files is set to “**/*.{c,h,m,mm,cpp}”</p><p>We have two problems here:<br> — This podspec will install every <strong>c,h,m,mm,cpp</strong> file in the react native repo<br> — It will require a package.json to be located at <strong>../../package.json.</strong></p><p>To solve these problems:<br> — Change the source_files to point to the correct directory, in this case:</p><pre>s.source_files = “<strong>Libraries/FBLazyVector/</strong>**/*.{c,h,m,mm,cpp}”</pre><p>— Make sure that the package path is set to:</p><pre>package = JSON.parse(File.read(File.join(__dir__, &quot;..&quot;, &quot;..&quot;, &quot;package.json&quot;)))</pre><pre># we will place package json in that path in the next section</pre><p>This way, when we add <strong>FBLazyVector</strong> as a dependency to our SDK, only <strong><em>Libraries/FBLazyVector</em></strong> contents will be installed.</p><p>React native uses a bunch of other pods, to find all pods used by react native, check the following file:</p><pre>MySdk/ios/Podfile</pre><p>The exact changes we made to <strong>FBLazyVector podspec </strong>above has to be done for all other react native pods!</p><blockquote>I have already done this and uploaded the whole project to GitHub</blockquote><p><strong>Third party dependencies</strong></p><p>For third party dependencies, it is much easier, we can use the pod dependencies as the following:</p><pre>pod &#39;RNFastImage&#39;, :git =&gt; &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:DylanVann/react-native-fast-image.git&quot;, :tag=&gt; &#39;v8.3.3&#39;</pre><p>Here, we are using <strong>RNFastImage</strong> pod by just pointing to its repository. However, the SDK user will have to add this to his/her pods as CocoaPods has no idea where <strong>RNFastImage</strong> is located. If you want the user to just have a single dependency, add any other third party dependency to your podspec repo.</p><h3>Creating private Podspec repo</h3><p>After setting up all react native podspecs, we can create a private podspec repo. The goal is to be able to import react native dependencies as:</p><pre>pod &#39;React&#39;</pre><p>Looking at <strong>MySdk/ios/Podfile</strong><em> </em>mentioned above, react native requires the following dependencies:</p><pre>pod &#39;FBLazyVector&#39;<br>pod &#39;FBReactNativeSpec&#39;<br>pod &#39;RCTRequired&#39;<br>pod &#39;RCTTypeSafety&#39;<br>pod &#39;React&#39;<br>pod &#39;React-Core&#39;<br>pod &#39;React-CoreModules&#39;<br>pod &#39;React-RCTActionSheet&#39;<br>pod &#39;React-RCTAnimation&#39;<br>pod &#39;React-RCTBlob&#39;<br>pod &#39;React-RCTImage&#39;<br>pod &#39;React-RCTLinking&#39;<br>pod &#39;React-RCTNetwork&#39;<br>pod &#39;React-RCTSettings&#39;<br>pod &#39;React-RCTText&#39;<br>pod &#39;React-RCTVibration&#39;<br>pod &#39;React-cxxreact&#39;<br>pod &#39;React-jsi&#39;<br>pod &#39;React-jsiexecutor&#39;<br>pod &#39;React-jsinspector&#39;<br>pod &#39;Yoga&#39;<br>pod &#39;DoubleConversion&#39;<br>pod &#39;glog&#39;<br>pod &#39;Folly&#39;</pre><p>The Podspec repo should be structured as the following:</p><pre>.<br>+-- PodSpecRepo<br>|  +-- package.json // this is react native&#39;s package.json<br>|  +-- FBLazyVector // pod name<br>|  |  +-- 0.63.3 // pod version<br>|  |  |  +-- FBLazyVector.podspec // the amended podspec<br>|  +-- FBReactNativeSpec<br>|  |  +-- 0.63.3<br>|  |  |  +-- FBReactNativeSpec.podspec<br>|  +-- RCTRequired<br>|  |  +-- 0.63.3<br>|  |  |  +-- RCTRequired.podspec</pre><pre>.... the rest of the dependencies</pre><p>Upload you private repo to GitHub or Bitbucket. <strong>You can find the repo created in this article </strong><a href="https://github.com/AbdullahAsendar/react-native-private-repo"><strong>here</strong></a><strong>.</strong></p><h3><strong>Adding the pods to Podfile</strong></h3><p>Now we have all the pods needed for the react native app, add the following to <strong>MySdk-native</strong> Podfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59d5f0d803595e7ec7631280a50dc2a1/href">https://medium.com/media/59d5f0d803595e7ec7631280a50dc2a1/href</a></iframe><p><strong>Do not forget to add your podspec repo as a source on the top of of the Podfile</strong></p><p>After that, cd to <strong><em>MySdk-native</em></strong><em> </em>then<em> </em>execute:</p><pre>pod install --repo-update</pre><p>At this point, we can use react native classes inside our wrapper.</p><h3><strong>Run React Native inside the wrapper</strong></h3><p>Now we are all set, we want to start the react native app using the native wrapper that we created. This is explained and well documented in the official <a href="https://reactnative.dev/docs/integration-with-existing-apps/">react native docs</a>.</p><p>First, create a Swift class to be used as an interface for the SDK user, our class will simply contain one function that runs the react native app. That function will create a new RCTRootView and present it inside a controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14c7291745d90ee215759969f10f2097/href">https://medium.com/media/14c7291745d90ee215759969f10f2097/href</a></iframe><h3>Create a podspec for the SDK</h3><p>It is important to create a podspec for the SDK so users can easily add it to their apps. Nothing special here, just an ordinary podspec.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a5635b36cd8413dbba8af788b763061/href">https://medium.com/media/2a5635b36cd8413dbba8af788b763061/href</a></iframe><h3><strong>The SDK in action</strong></h3><p>Moment of truth! let us test the SDK.</p><p>Create a simple swift app with a single button that will start our SDK. We will call this app <strong>MySdk-poc</strong>. Cd into the created app and execute:</p><pre>pod init &amp;&amp; pod install</pre><p>Open the generated <strong>MySdk-poc.xcworkspace </strong>and add the following to the Podfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe2dee3d17abff0da211c7369e3d01e0/href">https://medium.com/media/fe2dee3d17abff0da211c7369e3d01e0/href</a></iframe><p>Then execute <strong>pod install</strong> again.</p><p>Create a button that will start react native on action:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/897df5593c07e305512fe27b5fd6ba82/href">https://medium.com/media/897df5593c07e305512fe27b5fd6ba82/href</a></iframe><p>Add the following to the <strong>info.plist</strong> of the poc:</p><pre>&lt;key&gt;NSAppTransportSecurity&lt;/key&gt;<br>     &lt;dict&gt;<br>  &lt;key&gt;NSExceptionDomains&lt;/key&gt;<br>  &lt;dict&gt;<br>   &lt;key&gt;localhost&lt;/key&gt;<br>   &lt;dict&gt;<br>    &lt;key&gt;NSTemporaryExceptionAllowsInsecureHTTPLoads&lt;/key&gt;<br>    &lt;true/&gt;<br>   &lt;/dict&gt;<br>  &lt;/dict&gt;<br> &lt;/dict&gt;</pre><p>This is needed only for debugging, to give the app the ability to connect to the metro bundler.</p><p>Start your react native project using <strong>yarn start </strong>then start the poc app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKBuVtoSFBQls3JZ3cullA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66u1IHnuu7asu_ZvJUjRfA.png" /></figure><h3>Notes</h3><p>— I used react native 0.61.5, other react native version may require different way of doing stuff.<br> — You may face some problems while building. For me, a lot of build problems were fixed by cleaning the build folder and building again.<br> — I am writing another article on how to setup production builds.</p><p><strong>Project files</strong></p><p>You can find all of the project files used in this article here:<br><a href="https://github.com/AbdullahAsendar/react-native-ios-sdk">https://github.com/AbdullahAsendar/react-native-ios-sdk</a></p><p>Thats all folks!<br>Abdullah Asendar</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=481d38f549bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>