2

I want to use React Native Pods into one of my iOS Apps which is built using Swift. I have bundled my React Native components into ios-main.jsbundle. I am consuming the routes as shown below:

class ContentViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func loadView() {
        loadReactNativeView()
    }

    func loadReactNativeView() {
        let jsCodeLocation = Bundle.main.url(forResource: "main-ios", withExtension: "jsbundle")!
        
        let rootView = RCTRootView(
            bundleURL: jsCodeLocation,
            moduleName: "YourApp",
            initialProperties: nil,
            launchOptions: nil
        )
        self.view = rootView
    }
}

and in order to use React, I have done pod installation with my podFile something like as shown below:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '13.0'

target 'yourreactnativeapp' do
  use_react_native!
end

This works fine but here's the problem, my ios file is a root git directory and so I can't go one level up... again to perform pod installation, even if I place the files into my ios directory that would mean uploading entire node modules, which doesn't seem like a good solution, is there a way that I could use something other than require_relative to install React Native pod dependencies remotely from somewhere? I am okay with uploading node modules into another git repo and then fetching it from there.

Shivam Sahil
  • 4,055
  • 3
  • 31
  • 62
  • I'm looking to do the same thing and coming to the realisation that I'll need to create a cocoapods repo to provide the react native pods. Did you go ahead with this approach? – darnmason May 17 '23 at 00:11
  • Yes that's the only feasible way as far as I know – Shivam Sahil May 17 '23 at 03:15
  • It'd be great to see your solution, perhaps you could answer your own Q? – darnmason May 17 '23 at 05:12
  • Hey @darnmason. sorry but I am really missing all of the context I did it long back. I should have updated the answer but unfortunately I don't even have all the React Native setup with me right now. – Shivam Sahil May 20 '23 at 02:57

0 Answers0