伺服器位址錯誤
運作時産生以下錯誤:Could not connect to development server.
1、URL位址設定
問題:
[objc] view plain copy
- 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位址,并且保證連接配接的是同一個網絡(例如:連接配接同一個路由的網絡)。
[objc] view plain copy
- jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
2、HTTP設定
[objc] view plain copy
- 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即可
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsQTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cGcq5yMwkzM1MjNwYmM1MjZ1MDOyYzX3ETOzYTM3EzLcVDMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.jpg)
提示
搖晃裝置來打開開發菜單(重新加載、調試,等等……),這跟模拟器下的指令類似(Cmd + R to reload,Cmd + D)
watchman無法啟動的問題
現象:
[javascript] view plain copy
- 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中運作,就會出現上面的錯誤,官方文檔并沒有給出提示,增加大家學習的難度。
參考:
1. 在裝置上運作React Native項目
2. React-Native Start的時候遇到的報錯