试了多种方法,这种最简单
第一步:创建最新的rn版本,命令使用:npx react-native init AwesomeProject
第二步:找到iOS目录下的Podfile文件,将此文件内的和原生文件的Podfile文件合并
贴一个暂时可用的例子
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
source 'https://github.com/CocoaPods/Specs.git'
platform:ios, '11.0'
target 'QinBei' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)
pod 'AAChartKit', :git => 'https://github.com/AAChartModel/AAChartKit.git'
pod 'SDWebImage', '~> 5.0.4'
pod 'AFNetworking', '~> 3.0', :subspecs => ['Reachability', 'Serialization', 'Security', 'NSURLSession']
pod 'SVProgressHUD', '~> 2.2.5'
pod 'JPush'
pod 'JSONKit-NoWarning', '~> 1.2'
#pod 'MJRefresh', '~> 3.1.15.3'
pod 'YYImage'
pod 'Masonry', '~> 1.1.0'
pod 'MBProgressHUD', '~> 1.1.0'
pod 'RATreeView', '~> 2.1.2'
pod 'MJExtension', '~> 3.0.17'
pod 'XLForm', '~> 4.1'
#pod 'LMForm'
pod 'iOS-Echarts'
pod 'JDragonTypeButtonView','~> 0.0.3'
use_flipper!()
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
end
end
end
end
第三步:将rn自带的iOS目录下文件替换成原生项目下的文件
第四步:进入iOS目录,执行pod install
第五步:运行(例子参考https://reactnative.cn/docs/integration-with-existing-apps)
可能出现错误解决方法:
associated type descriptor for Swift.XXXXXXXXX
在iOS目录创建一个空的swift文件即可