Reputation: 895
I'm trying to integrate react native app to existing IOS app. But i get the error below.
Error Log : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RCTCxxBridge devSettings]: unrecognized selector sent to instance 0x14d3317c0' *** First throw call stack: (0x18b500f20 0x183386018 0x18b60a480 0x18b49dfb4 0x18b49d8d0 0x11232eaec 0x11232be48 0x111578b98 0x11157a7bc 0x11158ed18 0x11158f4d8 0x1e83578f8 0x1e83540cc) libc++abi: terminating due to uncaught exception of type NSException
react: 18.3.1
react-native : 0.74.2
Sample codes from : https://github.com/duytq94/demo-integrate-react-native/tree/master
RNViewManager.swift
import Foundation
import React
class RNViewManager: NSObject {
var bridge: RCTBridge?
static let sharedInstance = RNViewManager()
func createBridgeIfNeeded() -> RCTBridge {
if bridge == nil {
bridge = RCTBridge.init(delegate: self, launchOptions: nil)
}
return bridge!
}
func viewForModule(_ moduleName: String, initialProperties: [String : Any]?) -> RCTRootView {
let viewBridge = createBridgeIfNeeded()
let rootView: RCTRootView = RCTRootView(
bridge: viewBridge,
moduleName: moduleName,
initialProperties: initialProperties)
return rootView
}
}
extension RNViewManager: RCTBridgeDelegate {
func sourceURL(for bridge: RCTBridge!) -> URL! {
#if DEBUG
return URL(string: "http://192.168.1.25:8081/index.bundle?platform=ios")
#else
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}
}
Sample Button Click Code :
let rootView = RNViewManager.sharedInstance.viewForModule(
"MyReactNativeApp",
initialProperties: ["message_from_native": "messageFromNative"])
let reactNativeVC = UIViewController()
reactNativeVC.view = rootView
reactNativeVC.modalPresentationStyle = .fullScreen
present(reactNativeVC, animated: true)
Upvotes: 1
Views: 281
Reputation: 895
On Xcode, you have to add $(inherited) parameter to the "Other Linker Flags" which is under App -> Build Settings -> Linking - General
Upvotes: 0