美文网首页iOS埋坑
iOS原有项目中添加 React Native

iOS原有项目中添加 React Native

作者: 幸福的李雨龙 | 来源:发表于2016-03-16 12:57 被阅读187次

1.创建cocoapods文件

# Depending on how your project is organized, your node_modules directory may be

# somewhere else; tell CocoaPods where you've installed react-native from npm

pod 'React', :path => './node_modules/react-native', :subspecs => [

'Core',

'RCTImage',

'RCTNetwork',

'RCTText',

'RCTWebSocket',

# Add any other subspecs you want to use in your project

]

【解释】path对应的是 你的js基础组件的位置。最好复制到项目的目录中。不过根据官方默认教程来说也的确是在项目的根目中

2.布局所需文件

2.1当然是拷贝 js的组件。可以使用 react-native -init XXX.等待完成之后,将js组件复制过来

2.2创建存放js的文件夹ReactComponent

3.开启RN的服务

使用终端 cd 到项目中的 node_modules/react-native目录下然后执行

npm run start -- -- root 工程根目录/ReactComponen

然后你就可以点击xcode run了

4踩坑

4.1关于配置 url

NSURL*jsCodeLocation = [NSURLURLWithString:@"http://localhost:8081/ReactComponent/index.ios.bundle?platform=ios"];

明显是:ip:port/js目录/index.………

4.2 port冲突

lsof -i tcp:80801查看被占用的端口

kill -9 pid     pid为查找出的对应值,然后重新 npmrun就行了

相关文章

网友评论

    本文标题:iOS原有项目中添加 React Native

    本文链接:https://www.haomeiwen.com/subject/wdmqlttx.html