React Native在开发过程中遇到的一些问题(俗称:坑)

服务器地址错误

运行时产生以下错误:Could not connect to development server.

1、URL地址设置

问题:

Could not connect to development server.

Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate

URL: http://localhost:8081/index.ios.bundle?platform=ios&dev=true
2016-08-29 17:52:29.307 [error][tid:main][RCTWebSocketManager.m:84] WebSocket connection failed with error Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused"


解决:

AppDelegate.m文件中,把一下代码中的localhost改为你电脑的IP地址,并且保证连接的是同一个网络(例如:连接同一个路由的网络)。

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

2、HTTP设置

2016-08-29 18:01:20.273 AwesomeProject[688:263429] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
2016-08-29 18:01:20.316 [fatal][tid:main] Could not connect to development server.

Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate

URL: http://10.240.139.46:8081/index.ios.bundle?platform=ios&dev=true

开启ATS即可



提示

摇晃设备来打开开发菜单(重新加载、调试,等等……),这跟模拟器下的命令类似(Cmd + R to reload,Cmd + D)




watchman无法启动的问题

现象:

watchman--no-pretty get-sockname returned with exit code 1


这个问题不影响app的运行,但是有红色的Error总感觉不好


解决方法:


修改权限

sudo chown -R `whoami` /usr/local


重新安装watchman 
brew link pcre 
brew install –HEAD watchman

brew uninstall watchman 

这时可能还是会遇到以下的错误


把错误提示的那些/usr/local下的文件先删除,然后执行"brew update"



然后安装watchman: "brew install -HEAD watchman"



出现不能"symlink"的错误,按照提示执行:


这样执行后,watchman就可能正常使用了



reactNative调用原生方法的问题

按照react-native中文网上的教程,学习iOS下的原生模块(iOS 日历模块演示), 功能就是JS调用Object-C定义的方法,代码都是照抄,但是运行的时候出现以下错误,一直没找到解决办法。


后来发现OC代码的修改,如果要看效果,必须是通过Xcode运行,才能调用到原生方法,如果是在Deco中运行,就会出现上面的错误,官方文档并没有给出提示,增加大家学习的难度。



参考:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
React and React Native by Adam Boduch English | 8 Mar. 2017 | ASIN: B01MQ1GHCS | 604 Pages | AZW3 | 7.22 MB Key Features Build React and React Native applications using familiar component concepts Dive deep into each platform, from routing in React to creating native mobile applications that can run offline Use Facebook's Relay, React and GraphQL technologies, to create a unified architecture that powers both web and native applications Book Description React and React Native allow you to build cross-platform desktop and mobile applications using Facebook's innovative UI libraries. Combined with the Flux data architecture and Relay, you can now create powerful and feature-complete applications from just one code base! This book is split into three parts. The first part shows you how to start crafting composable UIs using React, from rendering with JSX and creating reusable components through to routing and creating isomorphic applications that run on Node. We then move on to showing you how to take the concepts of React and apply them to building Native UIs using React Native. You'll find out how to build responsive and streamlined UIs that can properly handle user interactions in a mobile environment. You'll also learn how to access device-specific APIs such as the geolocation API, and how to handle offline development with React Native. Finally, we'll tie all of these skills together and shows you how you can create React applications that run on every major platform. As well as understanding application state in depth, you'll learn how to leverage Relay to make feature-complete, data-driven web and native mobile applications. What you will learn Craft reusable React components Control navigation using the React Router to help keep your UI in sync with URLs Build isomorphic web applications using Node.js Use the Flexbox layout model to create responsive mobile designs Leverage the native APIs of Android and iOS to build engaging applications with React Native Respond to gestures in a way that's intuitive for the user Use Relay to build a unified data architecture for your React UIs About the Author Adam Boduch has been involved with large-scale JavaScript development for nearly 10 years. Before moving to the front end, he worked on several large-scale cloud computing products, using Python and Linux. No stranger to complexity, Adam has practical experience with real-world software systems, and the scaling challenges they pose. He is the author of several JavaScript books, including Flux Architecture, and is passionate about innovative user experiences and high performance. Table of Contents Why React? Rendering with JSX Understanding Properties and State Event Handling – The React Way Crafting Reusable Components The React Component Lifecycle Validating Component Properties Extending Components Handling Navigation with Routes Server-Side React Components Mobile-First React Components Why React Native? Kickstarting React Native Projects Building Responsive Layouts with Flexbox Navigating Between Screens Rendering Item Lists Showing Progress Geolocation and Maps Collecting User Input Alerts, Notifications, and Confirmation Responding to User Gestures Controlling Image Display Going Offline Handling Application State Why Relay and GraphQL? Building a Relay React App

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值